The memory size of large algebraic data types

Let's say I have a data type with a lot of constructors.

data ManyValues
  = Value0
  | Value1
  | Value2
  ...
  | Value255
  | Value256
  deriving (Show,Eq)

How much memory is there for any value of this data type? My initial understanding was that each constructor is an 8-bit word in memory, but that if there are more constructors in the data type than 8 bits, possible values ​​are possible. Does the constructor contain up to 16 bits, and so on, until it can address the entire range of constructors present in the data type? Or am I confused all this?

+4
source share
1 answer

, 1 (.. ). , 1 1 000 000, 1 .

, GHC . (, True.)

, thunk ( ), GHC thunk "" node, . .

+3

Source: https://habr.com/ru/post/1651490/


All Articles