3 ms·
The example algebraic data type isn't an algebraic data type at all. It's a single type with a single type constructor. How is this different from a regular cla
by doomrobo 10y ago
The example algebraic data type isn't an algebraic data type at all. It's a single type with a single type constructor. How is this different from a regular class?
- andolanra 10y agoIt looks like data declarations get translated to immutable subclasses of collections.namedtuple in such a way that you can match on the resulting values. So it's really less like an algebraic data type and more like one of Scala's case classes.
- abecedarius 10y agoWhen I used namedtuple that way it tended to blow up on me, because namedtuples implement 'dunder' methods to act as sequences, which is not what I expect for some random algebraic datatype. This makes bugs manifest as very head-scratching behavior. Nowadays I use my own struct type builder with only the equivalent of 'derives Show' and such.