Case expressions, matching, and "constants"

Graham Klyne GK@ninebynine.org
Thu, 17 Jul 2003 14:52:04 +0100


At 12:03 17/07/03 +0100, Bayley, Alistair wrote:
>This is what I've turned it into to get it to work. It seems a bit clumsy;
>is there a better way to write this?
>
> > test n =
> >       case True of
> >               _ | n == one -> "one"
> >                 | n == two -> "two"
> >                 | otherwise -> "three"

The 'case' is somewhat redundant.  How about:

 > test n | n == one  = "one"
 >        | n == two  = "two"
 >        | otherwise = "three"

#g


-------------------
Graham Klyne
<GK@NineByNine.org>
PGP: 0FAA 69FF C083 000B A2E9  A131 01B9 1C7A DBCA CB5E