two easy questions

Dylan Thurston dpt@math.harvard.edu
Sun, 23 Feb 2003 09:35:52 -0500


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

On Fri, Feb 21, 2003 at 12:14:04AM -0500, Mike T. Machenry wrote:
> Hmm, that does seem like alot of code to say such a little thing. Is it
> possible to come at the problem from the other direction? By this I mean I
> am trying to have two sets of symbols be enumerated together. This soluti=
on
> I asked for tries to impose the enumeration over the data. Can I define
>=20
> data Player =3D Red | Green | Blue | MrX deriving (Enum)
>=20
> and then use type classes or something else to say that MrX is a fugitive=
 and
> the others are detectives such that I can pattern match on them? I have
> functions that recur over the Player argument and terminate at MrX, but I=
 also
> want to be able to formally say that some functions cannot take a player =
that
> is Mrx, or can only take Mrx.

I think type classes would be overkill here.  What's wrong with

isDetective :: Player -> Bool
isDetective MrX =3D False
isDetective _ =3D True

?  (The pattern matching doesn't work quite the same way, but you can
use guards to acheive the same effect, especially with ghc's pattern
guards extension.)

Best,
	Dylan Thurston

--8t9RHnE3ZwKMSgU+
Content-Type: application/pgp-signature
Content-Disposition: inline

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

iD8DBQE+WNxIVeybfhaa3tcRAlKtAJ91jlHQwrV98g1gKiQ0d6ORAi1m5QCfZ0dg
ulXRcYkaR3Zcrt6lhi1cDpA=
=31Yv
-----END PGP SIGNATURE-----

--8t9RHnE3ZwKMSgU+--