[GHC] #10134: Pattern Matching Causes Infinite Type Error

GHC ghc-devs at haskell.org
Sat Aug 1 19:43:04 UTC 2015


#10134: Pattern Matching Causes Infinite Type Error
-------------------------------------+-------------------------------------
        Reporter:  dongen            |                   Owner:
            Type:  bug               |                  Status:  infoneeded
        Priority:  normal            |               Milestone:
       Component:  Compiler          |                 Version:  7.8.4
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |               Test Case:
      Blocked By:                    |                Blocking:
 Related Tickets:                    |  Differential Revisions:
-------------------------------------+-------------------------------------

Comment (by thomie):

 To reproduce this problem:

 * Download `T10134.hs` and `ClashPrelude.hs`, which is a further reduced
 version of `Dummy.lhs` above, without any dependencies.

 * Run `ghc-7.8.4 T10134.hs -fforce-recomp -XDataKinds -XTypeOperators
 -XConstraintKinds -XTypeFamilies -XNoMonomorphismRestriction
 -XNoMonoLocalBinds`.

 (I didn't add these as language pragmas to the file, to show that clash-
 ghc sets them)

 * This is the error:
 {{{
     Occurs check: cannot construct the infinite type: t0 ~ (t0 + 1) - 1
     The type variable ‘t0’ is ambiguous
     When checking that ‘dSnd’ has the inferred type ‘Bool’
     Probable cause: the inferred type is ambiguous
     In an equation for ‘nextDummy’:
         nextDummy d
           = Dummy {vec = vec dFst}
           where
               (dFst, dSnd) = nextDummy' d
 }}}

 To reproduce with clash-ghc itself, I did something like this:
 {{{
 $ cabal sandbox init
 $ cabal install --with-ghc=ghc-7.8.4 clash-ghc==0.4.1 --constraint=clash-
 lib==0.4.1
 $ ./cabal-sandbox/bin/clash -package-db=.cabal-sandbox/x86_64-linux-
 ghc-7.8.4-packages.conf.d/ T10134.hs`
 ...
 same error
 ...
 }}}

 What's going on is this:
 * clash-ghc is basically a copy of ghc-bin, with some modifications.

 * One of the modifications is that by default it sets `TypeFamilies` and
 some other language extensions, and unsets `MonoMorphismRestriction`.

 * Normally, when you set `TypeFamilies` (or `GADTs`), you also get
 `MonoLocalBinds`. clash-ghc doesn't call the code that does that however,
 and instead manipulates DynFlags directly.

 * So to reproduce the problem with just ghc, we have to set
 `TypeFamilies`, but unset `MonoLocalBinds`.

 `T10134.hs` compiles fine with ghc-7.10.2 and HEAD. It does show the
 following warning:
 {{{
     Redundant constraint: Positive (2 * (n + d))
     In the type signature for:
        nextDummy' :: Positive (2 * (n + d)) =>
                      Dummy n d -> (Dummy n d, Bool)
 }}}
 After removing that constraint, the example compiles with ghc-7.8.4 also.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10134#comment:17>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list