[Haskell-cafe] Newbie Question on type constructors

Benjamin Franksen benjamin.franksen at bessy.de
Mon Nov 1 19:16:59 EST 2004

On Monday 01 November 2004 23:40, Jon Fairbairn wrote:
> if Circle.destruct:: Shape -> (Double -> t) -> t -> t and
> similarly Square.destruct, we'd just have to write the case
> as
> Circle.destruct s f (Square.destruct s g (error "impossible"))
> ie the .destructs take a Shape, a function to apply if it
> matches and a value to return if it doesn't.

Ah, I see. It's rather more ugly but it is a better match for what Haskell 
does at the moment, isn't it? (IIRC patterns are matched in the order they 
appear in the source).

> Apart from matching up with the names there's not much to
> choose between one destructor and many, except possibly when
> one considers something like:
>    case e of
>      Square s -> ...
>      _ -> ...
> particularly if the type has more than two constructors.

True. Anyway, we don't really want to abandon pattern matching syntax, do we?


More information about the Haskell-Cafe mailing list