[Haskell-beginners] data type design question

Tillmann Rendel rendel at daimi.au.dk
Thu Jul 31 02:36:16 EDT 2008


Rafael Gustavo da Cunha Pereira Pinto schrieb:
> I was thinking:
> 
> data TPrimitive= TString String | TInt Integer
> data TComplex = TList [TPrimitive] | TDict [(String,TPrimitive)]
> data T = TPrimitive | TComplex
> 
> Would that work?

This is not what Markus wants for two reasons:

(1) T is just an enumeration here, maybe you meant

       data T = TPrimitive TPrimitive | TComplex TComplex

     instead.

(2) Lists and dictionaries are allowed to contain complex values,
     but lists are not allowed to contain values of different "types".

   Tillmann


More information about the Beginners mailing list