A question about overloading

Hamilton Richards hrichrds at swbell.net
Sat Nov 8 22:14:33 EST 2003


At 7:02 PM -0800 11/8/03, Ryoko Nanase wrote:
>Hello, everyone.
>I can't use any instance of type "Int". Every other type is working, 
>but not Int and Float.
>
>In the following source, "isTrue 'T'" is working, but "isTrue 0" is 
>not working, printing "Unresolved overloading - Type : (Num a, 
>Boolable a) => Bool". Can you tell me how to solve this problem? 
>Source codes are ONLY eight lines, so please help me! Thanks in 
>advance.
>
>
>class Boolable t where
>         isTrue :: t -> Bool
>
>instance Boolable Char where
>         isTrue 'T' = True
>         isTrue _ = False
>
>instance Boolable Int where
>         isTrue 0 = False
>         isTrue _ = True
>
>

The problem isn't in your code-- it's the lack of context to resolve 
overloaded numerals. Here are a few illustrative examples:

Hugs session for:
/usr/local/lib/hugs/lib/Prelude.hs
/Users/ham/Desktop/test.lhs
Main> isTrue 3
ERROR - Unresolved overloading
*** Type       : (Num a, Boolable a) => Bool
*** Expression : isTrue 3

Main> isTrue (3::Int)
True
Main>
Main> isTrue (length [])
False
Main> isTrue (length "abcde")
True
Main>

Regards,

--Ham
-- 
------------------------------------------------------------------
Hamilton Richards, PhD           Department of Computer Sciences
Senior Lecturer                  The University of Texas at Austin
512-471-9525                     1 University Station C0500
Taylor Hall 5.138                Austin, Texas 78712-1188
ham at cs.utexas.edu                hrichrds at swbell.net
------------------------------------------------------------------


More information about the Haskell mailing list