[Haskell] Re: [Haskell-cafe] Basic Haskell Types Question

Wolfgang Jeltsch wolfgang at jeltsch.net
Fri Sep 16 10:04:40 EDT 2005


Am Freitag, 16. September 2005 14:19 schrieb Adam Wyner:
> [...]

> But, what I don't understand or like is that the type of the whole
> is given as [[Char]], not what I thought it would be, namely PropList.
> Nor is it [String].

These three are essentially the same type.  So a Haskell system may use 
whatever representation the developer of it thought is the best one.

> [...]

> Am I supposed to be using newtype or data declarations here?  How would
> I do this?  I looked around for information in the usual sources,
> but haven't found an answer.

You should use newtype declarations since they introduce a truely new type.  
Apart from solving your problem, this has further advantages.  A list of 
complex numbers may, for example, denote a polynomial or a digital filter.  
If you use type synonyms, as you did so far, you could use a digital filter 
where a polynomial is needed or vica versa.  With newtype declarations you 
couldn't confuse these two different things.  In addition, you could restrict 
instance declarations to just polynomials or digital filters and implement 
the methods so that they are meaningful for just this particular kind of 
thing.

> Thanks,
> Adam Wyner

Best wishes,
Wolfgang


More information about the Haskell mailing list