Novice question

Tom Pledger Tom.Pledger@peace.com
Mon, 23 Apr 2001 15:41:47 +1200


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