|
RE: instance not found: msg#00004lang.haskell.glasgow.bugs
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> |
|---|---|---|
| Previous by Date: | RE: ghci failed to load static archive, Simon Marlow |
|---|---|
| Next by Date: | RE: class not used, error not detected, Simon Peyton-Jones |
| Previous by Thread: | instance not found, Wolfgang Jeltsch |
| Next by Thread: | class not used, error not detected, Wolfgang Jeltsch |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |