News for hackers. Stuff that matters.
Re:Pitfalls in Haskell by dllthomas on Monday August 22, 2016 @11:18AM (#12336907)
Regarding heterogeneous fields across constructors...

I agree that this is poor design.

Field accessors for a field present in one constructor and absent in others should give a Maybe.

I'm not certain what should be done for the case of different types. Packaging it up in an Either seems possible, but the obvious approach would make the shape of the return type depend on the order in which I've listed my constructors, which is ugly... Refusing to generate the accessor function seems okay. Disallowing the collision - effectively the current state - isn't so bad.

In practice, the rule others have mentioned works fine: pretend Haskell doesn't support named fields in types with more than one constructor. The RecordWildCards extension also makes traditional Haskell records more pleasant to work with.

There are no comments on this comment yet.