[GHC] #9755: Unhelpful error message when -XScopedTypeVariables is omitted (was: Monomorphism related Ix/Vector error when code is loaded by GHCi/cabal repl)
GHC
ghc-devs at haskell.org
Mon Nov 3 12:57:39 UTC 2014
#9755: Unhelpful error message when -XScopedTypeVariables is omitted
-------------------------------------+-------------------------------------
Reporter: bitemyapp | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: GHCi | Version: 7.8.3
Resolution: | Keywords:
Operating System: | Architecture: Unknown/Multiple
Unknown/Multiple | Difficulty: Unknown
Type of failure: | Blocked By:
None/Unknown | Related Tickets:
Test Case: |
Blocking: |
Differential Revisions: |
-------------------------------------+-------------------------------------
Comment (by simonpj):
I believe that the real problem is that in the definition of
{{{
vecIndexIx :: (Ix ix, Bounded ix) => Vector a -> ix -> a
vecIndexIx vec ix = vec ! Ix.index (minBound :: ix, maxBound :: ix) ix
}}}
you probably think that the uses of `ix` in the RHS mean the same `ix` as
in the type signature. To achieve that you need `-XScopedTypeVariables`
and an explicit `forall`:
{{{
vecIndexIx :: forall a ix. (Ix ix, Bounded ix) => Vector a -> ix -> a
vecIndexIx vec ix = vec ! Ix.index (minBound :: ix, maxBound :: ix) ix
}}}
Now it works fine. What you wrote is equivalent to
{{{
vecIndexIx vec ix = vec ! Ix.index (minBound :: forall ix. ix,
maxBound :: forall ix. ix) ix
}}}
where the type signature `blah :: ix` is universally quantified to `blah
:: forall ix. ix`.
It's an easy mistake to make. It might be a good idea if GHC spotted type
variables that have the same name as one belonging to an enclosing, but
un-scoped, type signature, and suggested this change. If someone wanted
to try that, I could advise.
Simon
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9755#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list