Missing associated type instance not reported with error
I noticed this SO question was caused by a warning disappearing as a result of the error it caused.
{-# language TypeFamilies, DataKinds #-}
module NoWarning where
data Nat = Zero | Succ Nat deriving Show
class FromList a where
type Item a :: *
fromList :: [Item a] -> a
instance FromList Nat where
fromList [] = Zero
fromList (a:as) = Succ (fromList as :: Nat)
fish :: Nat
fish = fromList [(),(),()]
If you delete fish, you get a nice warning:
NoWarning.hs:8:1: warning: [-Wmissing-methods]
• No explicit associated type or default declaration for ‘Item’
• In the instance declaration for ‘FromList Nat’
|
8 | instance FromList Nat where
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^...
But with fish, all you get is
NoWarning.hs:13:18: error:
• Couldn't match expected type ‘Item Nat’ with actual type ‘()’
• In the expression: ()
In the first argument of ‘fromList’, namely ‘[(), (), ()]’
In the expression: fromList [(), (), ()]
|
13 | fish = fromList [(),(),()]
|
That warning is the proper explanation of the problem, and it's just missing!
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.6.3 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |