
Is this a good place for novice questions? I have just started to try to learn Haskell, and am using Hugs to start with. When I write the not-very-useful function, greaterthan 0 _ _ = False greaterthan _ (x:xs) (y:ys) = x > y and test it, Main> greaterthan 2 [3] [4] False Main> greaterthan 3 [4] [3] True Main> greaterthan 0 [4] [3] False Main> greaterthan 0 [] [] ERROR: Unresolved overloading *** Type : Ord a => Bool *** Expression : greaterthan 0 [] [] Main> ...I don't understand what the problem is. I'm guessing that the problem is with the use of > and it not knowing which 'version' of > to use, but it doesn't need to know because we're not matching with that line anyway. I hope that didn't sound quite as confused as I am. (-: Is there anything easy someone can say that will enlighten me as to why things are as they are? (I understand that Ord is a set of types and that you can probably only apply > to things that are in it, and that > is overloaded somehow.) Thanks. -- Mark

Mark Carroll writes: | Is this a good place for novice questions? Yes, either here or on http://haskell.org/wiki/wiki | greaterthan 0 _ _ = False | greaterthan _ (x:xs) (y:ys) = x > y : | Main> greaterthan 0 [] [] | ERROR: Unresolved overloading | *** Type : Ord a => Bool | *** Expression : greaterthan 0 [] [] | | Main> | | ...I don't understand what the problem is. I'm guessing that the problem | is with the use of > and it not knowing which 'version' of > to use, but | it doesn't need to know because we're not matching with that line anyway. | I hope that didn't sound quite as confused as I am. (-: Your guess is basically right. The error can be fixed by specifying `the type of element that the lists do not contain', so to speak. greaterthan 0 [] ([] :: [()]) -- empty list of () greaterthan 0 [] ([] :: [Bool]) -- empty list of Bool greaterthan 0 [] "" -- empty list of Char This need for an explicit type signature is quite common in out-of-context tests at an interpreter's prompt, but rarer in actual programs. HTH. Tom

On 22-Apr-2001, Mark Carroll wrote:
greaterthan 0 _ _ = False greaterthan _ (x:xs) (y:ys) = x > y ... Main> greaterthan 0 [] [] ERROR: Unresolved overloading *** Type : Ord a => Bool *** Expression : greaterthan 0 [] []
...I don't understand what the problem is. I'm guessing that the problem is with the use of > and it not knowing which 'version' of > to use,
Yes.
but it doesn't need to know because we're not matching with that line anyway.
The type checker doesn't know that.
The type checker only takes into account the types of the arguments,
not their values, so it can't tell when an ambiguity like this
doesn't matter because the ambiguous code won't be executed.
--
Fergus Henderson
participants (3)
-
Fergus Henderson
-
Mark Carroll
-
Tom Pledger