|
Derivable type classes bug?: msg#00030lang.haskell.glasgow.bugs
Hi, Take a look at the following program, making use of derivable type classes. >>> module Bug where import Data.Generics class Foo a where foo :: a -> Int foo{| Unit |} _ = 1 foo{| a :*: b |} _ = 2 foo{| a :+: b |} _ = 3 instance Foo [a] <<< GHC 6.2.2 produces the following error message: >>> Bug.hs:12: Could not deduce (Foo a) from the context (Foo [a]) arising from use of `foo' at Bug.hs:12 <<< Why is the context needed? 'foo' is not a recursive function? I guess it is because the default declaration is split up into several instances: >>> instance Foo Unit where foo _ = 1 instance (Foo a, Foo b) => Foo (a :*: b) where foo _ = 2 instance (Foo a, Foo b) => Foo (a :+: b) where foo _ = 3 <<< Why not generating: >>> instance Foo Unit where foo _ = 1 instance Foo (a :*: b) where foo _ = 2 instance Foo (a :+: b) where foo _ = 3 <<< when the context is not needed? (My motivation is: I have a class like this: class Arbitrary a => Shrink a where shrinkSub :: a -> [a] shrinkSub{| ... |} = ... shrink ... The definition of shrinkSub is not recursive, it calls a function 'shrink' from the Arbitrary class instead.) Regards, /Koen PS. Has the implementation of Generics changed from some earlier compiler version (GHC 5.xx)? I have code lying around that I am almost certain of used to compile with an earlier version of GHC (that I do not have access to anymore).
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Readline on Windows?, Koen Claessen |
|---|---|
| Next by Date: | [ ghc-Bugs-1069656 ] ghc-ghci inconsisteny, SourceForge.net |
| Previous by Thread: | Readline on Windows?, Koen Claessen |
| Next by Thread: | RE: Derivable type classes bug?, Simon Peyton-Jones |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |