instance not found
Simon Peyton-Jones
simonpj at microsoft.com
Tue Sep 2 03:20:15 EDT 2003
When you type
1+5
to the GHCi prompt, the expression has type
Num a => a
and the defaulting mechanism (4.3.4 in the Report) chooses a=Integer,
and then solves the Num constraint.
The defaulting mechanism only works for standard classes, not for
user-defined ones.
You have an expression with type
C (a,b) => Int
If you instantiated a=(Int,Int), b=Int, the result would be 3.
If you instantiated a=Int, b=Int, the result would be 2.
So the result depends on how you instantiate the free type variables,
and the class is not a standard one, GHC correctly bleats.
Mind you, the error message could be better, I suppose. But I'm not
sure what a perfect error message would say.
Simon
| -----Original Message-----
| From: glasgow-haskell-bugs-admin at haskell.org
[mailto:glasgow-haskell-bugs-admin at haskell.org] On
| Behalf Of Wolfgang Jeltsch
| Sent: 01 September 2003 05:08
| To: GHC-Bugs
| Subject: instance not found
|
| Hello,
|
| I have the following code:
| class C a where
| f :: a -> Int
|
| instance C (a,b) where
| f = const 2
|
| instance C ((a,b),c) where
| f = const 3
|
| If I load this code into ghci with switches -fglasgow-exts and
| -fallow-overlapping-instances and enter f (1,2), I get this message:
| <interactive>:1:
| No instance for (C (t, t1))
| arising from use of `f' at <interactive>:1
| In the definition of `it': f (1, 2)
|
| I cannot see why f (1,2) shouldn't be acceptable, so I suppose it's a
bug. Am
| I missing something?
|
| I'm using GHC 5.04.3.
|
| Wolfgang
|
| _______________________________________________
| Glasgow-haskell-bugs mailing list
| Glasgow-haskell-bugs at haskell.org
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
More information about the Glasgow-haskell-bugs
mailing list