logo       

RE: instance not found: msg#00004

lang.haskell.glasgow.bugs

Subject: RE: instance not found

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@xxxxxxxxxxx
[mailto:glasgow-haskell-bugs-admin@xxxxxxxxxxx] 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@xxxxxxxxxxx
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise