Case expressions, matching, and "constants"
Fri, 18 Jul 2003 22:10:57 +0200
Content-Type: text/plain; charset=us-ascii
On Thu, Jul 17, 2003 at 12:03:19PM +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 =3D
> > case True of
> > _ | n =3D=3D one -> "one"
> > | n =3D=3D two -> "two"
> > | otherwise -> "three"
Or you might want to use something like this:
(depending on how much your example resembles the actual code
and the number of variables you want to match)
module Main where
one =3D 1
two =3D 2
test n =3D maybe d id (n `lookup` m)
m =3D [(one, "one")
d =3D "three"
Nobody can be exactly like me. Even I have trouble doing it.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
-----END PGP SIGNATURE-----