classes and instances

Russo, Tom tom@studentuniverse.com
Thu, 4 Oct 2001 11:31:59 -0400


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_000_01C14CE9.B5609060
Content-Type: text/plain;
	charset="iso-8859-1"

Hello,

I'm learning haskell and I'm having some trouble with type classes.  I
understand them conceptually, but when I try to create an instance I run
into problems.  As a simple example, I create a class called ToInt:

>	class ToCh a where
>		int :: a -> Int

Then I create an instance:

>	instance ToInt Int where:
>		int n = n

However, when I try to use the function int :: Int -> Int at the hugs
prompt, I get the following error message:

Main> int 5
ERROR - Unresolved overloading
*** Type       : (Num a, ToInt a) => Int
*** Expression : int 5

Can someone explain what the problem is, and how to interpret the error
message I'm getting?

thanks
_t



------_=_NextPart_000_01C14CE9.B5609060
Content-Type: application/ms-tnef
Content-Transfer-Encoding: base64

eJ8+IgYPAQaQCAAEAAAAAAABAAEAAQeQBgAIAAAA5AQAAAAAAADoAAEIgAcAGAAAAElQTS5NaWNy
b3NvZnQgTWFpbC5Ob3RlADEIAQWAAwAOAAAA0QcKAAQACwAfADsABABPAQEggAMADgAAANEHCgAE
AAsAIAAEAAQAGQEBCYABACEAAAA1NERFNkFDMTI5QjhENTExQkUwQzAwRDBCNzRBMERENgBHBwEE
gAEAFgAAAGNsYXNzZXMgYW5kIGluc3RhbmNlcwApCAENgAQAAgAAAAIAAgABA5AGAIwHAAAuAAAA
AwAJWQMAAAACAXEAAQAAABYAAAABwUzpsWSSOY1JKixJ4qFJJbd2AIulAAADAN4/r28AAAMAB4AI
IAYAAAAAAMAAAAAAAABGAAAAAFKFAAB9bgEAHgAJgAggBgAAAAAAwAAAAAAAAEYAAAAAVIUAAAEA
AAAEAAAAOS4wAAsAEYAIIAYAAAAAAMAAAAAAAABGAAAAAAaFAAAAAAAAAwASgAggBgAAAAAAwAAA
AAAAAEYAAAAAAYUAAAAAAAALAACACCAGAAAAAADAAAAAAAAARgAAAAADhQAAAAAAAAsAG4AIIAYA
AAAAAMAAAAA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