[Haskell-cafe] Newbie Question on type constructors
zednenem at psualum.com
Mon Nov 1 22:27:48 EST 2004
Benjamin Franksen writes:
> On Monday 01 November 2004 23:40, Jon Fairbairn wrote:
> > 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?
Explicit destructor functions are nice when working in a point-free
fashion. Consider these:
c1 = someComputation >>= maybe mzero return
c2 = do
x <- someComputation
case x of
Just x' -> return x'
Nothing -> mzero
On the other hand, this function (which I actually have in my code) may
be over-doing it:
swap = maybe (Right Nothing) (either Left (Right . Just))
David Menendez <zednenem at psualum.com> <http://www.eyrie.org/~zednenem/>
More information about the Haskell-Cafe