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

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). I'm curious as to why my class declaration compiles in GHC, as there doesn't seem to be any way to use it. -Arjun On Aug 7, 2004, at 01:06, camarao@dcc.ufmg.br wrote:
Hi Arjun.
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)]
Then don't forget to start the compiler/interpreter with -fglasgow-exts.
Hope this helps.
Regards,
Carlos

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

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

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
participants (4)
-
Arjun Guha
-
camarao@dcc.ufmg.br
-
Stefan Holdermans
-
Stefan Holdermans