[Haskell-beginners] Can fields in a record be optional?

David Virebayre dav.vire+haskell at gmail.com
Mon Jul 18 08:20:24 CEST 2011


I'm not sure I would model your datatype this way, I don't like the
idea to put unnecessary undefined values in the case of subcontracts.

I would instead

data Contract = Contract  { currency :: Currency, payments :: Double }
              | SubContract { contracts :: [Contract] }

one c  =  Contract { currency = c, payments = 1 }


and          :: Contract -> Contract -> Contract
(and) c1 c2  =  Subcontract { contracts = [c1, c2] }



More information about the Beginners mailing list