[Haskell-cafe] Type classes... popular for newbies, isn't it?

Stefan Holdermans stefan at mimmick.nl
Sat Aug 7 02:27:53 EDT 2004


Arjan,

AG> I'm curious as to why my class declaration
AG> compiles in GHC, as there doesn't seem to
AG> be any way to use it.

 > class (Ord st) => MinimaxState st where
 >   successors :: forall a . st -> [(a, st)]
 >   terminal   :: st -> True

Any implementation of the successors method needs to produce values of 
an arbitrarely type a. Hence, it can only produce the empty list or a 
list of pairs that all have bottom as their first component.

 > instance MinimaxState Bool where
 >   successors = const []
 >   terminal   = not

 > instance MinimaxState Int where
 >   successors n = [(undefined, pred n), (undefined, succ n)]
 >   terminal 0   = True
 >   terminal n   = False

HTH,

Stefan



More information about the Haskell-Cafe mailing list