[Haskell-beginners] Type constructors sharing a common field

John M. Dlugosz ngnr63q02 at sneakemail.com
Wed Apr 30 14:54:27 UTC 2014

On 4/29/2014 12:42 AM, Lorenzo Tabacchini wrote:
>> 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.

That reminds me of database design:  Normalize! In this case, Daniel's suggestion is in 
line with the theory.  With varying numbers of fields between the different kinds of 
people, it suggests making separate tables and joining them to produce the child or adult 

More generally, perhaps database schema rather than Object Oriented is a better place to 
transfer engineering skills from when it comes to designing the information model.


More information about the Beginners mailing list