[Haskell-beginners] Type constructors sharing a common field

Lorenzo Tabacchini lortabac at gmx.com
Tue Apr 29 05:42:13 UTC 2014


> Yes, there is:
>
>  data Person = Child { personAge :: Int, school :: School }
>              | Adult { personAge :: Int, job :: Job }
>
>
> No extension needed!


Thanks!
This helps reduce the number of field names, but it does not address the main problem, which is the obligation of pattern matching on all constructors.
The Person type is just a simple example. If you have a lot of constructors repeating all of them without a real reason can be time-consuming and boring.

I am aware that the real reason of the problem may be a wrong architecture, but I still have the feeling that my solution does have some use cases.



More information about the Beginners mailing list