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

camarao at dcc.ufmg.br camarao at dcc.ufmg.br
Sat Aug 7 11:06:59 EDT 2004


>> How about inserting one more parameter, "action", in your class
>> definition:
>> class (Ord st) => MinimaxState st action where
>>    successors:: st -> [(action,st)]
>>    terminal:: st -> Bool
>> instance MinimaxState Int Int where
>>    terminal i = i == 0
>>    successors i = [(1,i+1), (-1,i-1)]

> I'd rather not do that, but even if I did, the type-variable action
> would not be reachable in the terminal function.  I could specify a
> functional dependency st -> action (though I've never used it, it would
> be a fun to learn).

Right... you need the functional dependency because of "terminal", and in
general a type annotation for using it.

Carlos





More information about the Haskell-Cafe mailing list