4 ms·
It 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
by andolanra 10y ago
It 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.