
Hi, I'm new to Haskell and am getting this error: AlphaBeta.hs:1: Ambiguous type variable `v' in the top-level constraint: `Ord v' arising from use of `maxValue' at AlphaBeta.hs:12 in the following code: module AlphaBeta where -- Game states are instances of MinimaxState class MinimaxState st where successors:: st -> [(action,st)] terminal:: st -> Bool utility:: (Ord v) => st -> v minimaxDecision state = filter (\(_,st) -> utility st == v) (successors state) where v = maxValue state maxValue:: (MinimaxState state, Ord v) => state -> v maxValue state = if terminal state then utility state else (foldl max x xs) where (x:xs) = map (minValue.snd) (successors state) minValue:: (MinimaxState state, Ord v) => state -> v minValue state = if terminal state then utility state else (foldl min x xs) where (x:xs) = map (maxValue.snd) (successors state) Any hints would be appreciated. -Arjun

Arjun Guha wrote:
AlphaBeta.hs:1: Ambiguous type variable `v' in the top-level constraint: `Ord v' arising from use of `maxValue' at AlphaBeta.hs:12
Another person had a similar problem just the other week.. The error messages are different, but the problem is the same. Read the messages in this thread: http://www.haskell.org//pipermail/haskell-cafe/2004-July/006424.html Then read "Type classes with functional dependencies", Mark P. Jones, 2000 You can get the paper at http://www.cse.ogi.edu/~mpj Ben.

Thanks for the tip, I solved to problem by making MinimaxState a subclass of Ord, thereby removing the utility method entirely. It makes far more sense this way as well. -Arjun

This would be a great idea for something to put on the wiki, a page for each error message produced by the various compilers and a more in depth description of what it means and some ideas on how to track down the problem. John -- John Meacham - ⑆repetae.net⑆john⑈

At 11:19 26/07/04 -0700, John Meacham wrote:
This would be a great idea for something to put on the wiki,
a page for each error message produced by the various compilers and a more in depth description of what it means and some ideas on how to track down the problem.
A starting point might be the page based on Hugs errors in Simon Thompson's book: http://www.cs.kent.ac.uk/people/staff/sjt/craft2e/errors.html #g ------------ Graham Klyne For email: http://www.ninebynine.org/#Contact
participants (4)
-
Arjun Guha
-
Ben Lippmeier
-
Graham Klyne
-
John Meacham