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 solution
> I asked for tries to impose the enumeration over the data. Can I define
> 
> data Player = Red | Green | Blue | MrX deriving (Enum)
> 
> 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 = False
isDetective _ = 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

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to