Monad Maybe?

Dylan Thurston dpt@math.harvard.edu
Sat, 21 Sep 2002 18:42:12 -0400


--EuxKj2iCbKjpUGkD
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sat, Sep 21, 2002 at 12:56:13PM -0700, Russell O'Connor wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>=20
> [To: haskell-cafe@haskell.org]
>=20
> Is there a nicer way of writing the following sort of code?
>=20
> case (number g) of
>  Just n -> Just (show n)
>  Nothing ->
>   case (fraction g) of
>    Just n -> Just (show n)
>    Nothing ->
>     case (nimber g) of
>      Just n -> Just ("*"++(show n))
>      Nothing -> Nothing

You could write (using GHC's pattern guards):

show g | Just n =3D number g   =3D Just (show n)
       | Just n =3D fraction g =3D Just (show n)
       | Just n =3D nimber g   =3D Just ("*"++show n)
       | Nothing             =3D Nothing

Do I detect a program for analyzing combinatorial games being written?

--Dylan

--EuxKj2iCbKjpUGkD
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9jPXEVeybfhaa3tcRArsPAJ9LSm/YUfL4ohVMMeXYRI7Zkhup6gCdGu2n
y5HgyZSr1X6BW6G76uJZNTw=
=5bPk
-----END PGP SIGNATURE-----

--EuxKj2iCbKjpUGkD--