[GHC] #16213: Unnecessary error
GHC
ghc-devs at haskell.org
Tue Jan 22 14:04:32 UTC 2019
#16213: Unnecessary error
-------------------------------------+-------------------------------------
Reporter: pjljvdlaar | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.6.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by RyanGlScott):
Replying to [ticket:16213 pjljvdlaar]:
> Yet, both patterns are matched, i.e. '[] and (x ': xs),
> so I was surprised the compiler could not figure this out!
This isn't how type class instances work. Having an `Show (TermList '[])`
instance and a `Show (TermList (x ': xs))` instance doesn't imply an
instance for `forall (v :: [Bool]). Show (TermList v)`. In the instance
you're trying to write, GHC needs a `Show` instance for an arbitrary list
`v`, and GHC can't know //a priori// whether that list is `'[]` or `(_ ':
_)`.
That being said, there's not much sense in writing two separate `Show`
instances like this. Why not just combine them into a single instance,
like so?
{{{#!hs
instance Show (TermList v) where
show TNil = "Nil"
show (TCons a b) = "(Cons " ++ show a ++ " " ++ show b ++ ")"
}}}
This actually gives you an instance for `forall (v :: [Bool]). Show
(TermList v)`, so you avoid your earlier issue entirely.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/16213#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list