type families: poor error massages when lacking instances
The following code:
{-# LANGUAGE TypeFamilies #-}
type family Elem a
class Collection a where
cons :: Elem a -> a -> a
-- type instance Elem [a] = a
instance Collection [a] where
cons = (:)
clearly should not compile, as I have commented out the instance declaration for 'Elem [a]'.
The error message provided is less than helpful:
GHCi, version 6.8.0.20071012: http://www.haskell.org/ghc/ :? for help
Loading package base ... linking ... done.
[1 of 1] Compiling Main ( Test.hs, interpreted )
Test.hs:10:0:
Occurs check: cannot construct the infinite type: a = Elem [a]
When trying to generalise the type inferred for `cons'
Signature type: forall a. Elem [a] -> [a] -> [a]
Type to generalise: Elem [a] -> [a] -> [a]
In the instance declaration for `Collection [a]'
Failed, modules loaded: none.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 6.8 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | aslatter@gmail.com |
| Operating system | Unknown |
| Architecture | Unknown |