3 ms·
I got it the second time, but then again I already knew the answer. A nit: "a value can have multiple states" seems a bit confusing when we're talking about imm
by skybrian 8y ago
I got it the second time, but then again I already knew the answer. A nit: "a value can have multiple states" seems a bit confusing when we're talking about immutable values? Perhaps start out saying something about union types instead?
- tmountain 8y agoAlready locked for editing. For anyone reading this after the fact, I'd restate as follows. There are types called Sum Types which are formed by combining other types. Each value associated with a Sum Type is associated with a constructor (label for the value) and zero or more values associated with that constructor. As an example, a Maybe type could be defined to represent two states as follows: data Maybe a = Just a | Nothing When a value is present, it can be represented as: Just 3, Just "Hello", Just [1,2,3], etc. While missing values can be represented as: Nothing And yeah to be clear, we are talking about immutable values. Boxes that carry around some value (or lack thereof) that never change.