This is the smallest type signature I could find that still causes the problem. GHCi infers the type without issue, and when I annotate it with the correct type signature, the file is successfully compiled.
Using base-4.9.1.0, lens-4.14.1, and transformers-0.5.2.0
Trac metadata
Trac field
Value
Version
8.0.2
Type
Bug
TypeOfFailure
OtherFailure
Priority
normal
Resolution
Unresolved
Component
Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items
0
Show closed items
No child items are currently assigned. Use child items to break down this issue into smaller parts.
T14172.hs:7:19: error: • Occurs check: cannot construct the infinite type: a ~ g'1 a Expected type: (f'0 a -> f (f'0 b)) -> Compose f'0 g'1 a -> f (h a') Actual type: (Unwrapped (Compose f'0 g'1 a) -> f (Unwrapped (h a'))) -> Compose f'0 g'1 a -> f (h a') • In the first argument of ‘(.)’, namely ‘_Wrapping Compose’ In the expression: _Wrapping Compose . traverse In an equation for ‘traverseCompose’: traverseCompose = _Wrapping Compose . traverse • Relevant bindings include traverseCompose :: (a -> f b) -> g a -> f (h a') (bound at T14172.hs:7:1) |7 | traverseCompose = _Wrapping Compose . traverse | ^^^^^^^^^^^^^^^^^T14172.hs:7:19: error: • Couldn't match type ‘g’ with ‘Compose f'0 g'1’ ‘g’ is a rigid type variable bound by the inferred type of traverseCompose :: (a -> f b) -> g a -> f (h a') at T14172.hs:7:1-46 Expected type: (a -> f b) -> g a -> f (h a') Actual type: (a -> f b) -> Compose f'0 g'1 a -> f (h a') • In the expression: _Wrapping Compose . traverse In an equation for ‘traverseCompose’: traverseCompose = _Wrapping Compose . traverse • Relevant bindings include traverseCompose :: (a -> f b) -> g a -> f (h a') (bound at T14172.hs:7:1) |7 | traverseCompose = _Wrapping Compose . traverse | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
So this is odd. I tried running the example file (after installing the lens package) on GHC 8.2.1, and while it didn't loop forever, it //did// stack overflow:
$ /opt/ghc/8.2.1/bin/ghc Foo.hs[1 of 1] Compiling Foo ( Foo.hs, Foo.o )Foo.hs:7:19: error: • Reduction stack overflow; size = 201 When simplifying the following type: g ~ Compose f'0 g'0 Use -freduction-depth=0 to disable this check (any upper bound you could choose might fail unpredictably with minor updates to GHC, so disabling the check is recommended if you're sure that type checking should terminate) • In the expression: _Wrapping Compose . traverse In an equation for ‘traverseCompose’: traverseCompose = _Wrapping Compose . traverse |7 | traverseCompose = _Wrapping Compose . traverse | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Which certainly isn't good. I then tried to remove external dependencies:
{-# LANGUAGE FlexibleInstances #-}{-# LANGUAGE KindSignatures #-}{-# LANGUAGE MultiParamTypeClasses #-}{-# LANGUAGE RankNTypes #-}{-# LANGUAGE ScopedTypeVariables #-}{-# LANGUAGE TypeFamilies #-}{-# LANGUAGE UndecidableInstances #-}moduleLenswhereimportData.CoerceimportData.Functor.ComposeimportData.Functor.IdentityclassProfunctorpwheredimap::(a->b)->(c->d)->pbc->pad(#.)::Coerciblecb=>(b->c)->pab->pacinstanceProfunctor(->)wheredimapabcdbc=cd.bc.ab{-# INLINE dimap #-}(#.)_=coerce(\x->x::b)::forallab.Coercibleba=>a->b{-# INLINE (#.) #-}typeIsostab=forallpf.(Profunctorp,Functorf)=>pa(fb)->ps(ft)typeIso'sa=Isossaaiso::(s->a)->(b->t)->Isostabisosabt=dimapsa(fmapbt){-# INLINE iso #-}typeAnIsostab=Exchangeaba(Identityb)->Exchangeabs(Identityt)dataExchangeabst=Exchange(s->a)(b->t)instanceProfunctor(Exchangeab)wheredimapfg(Exchangesabt)=Exchange(sa.f)(g.bt){-# INLINE dimap #-}(#.)_=coerce{-# INLINE ( #. ) #-}withIso::AnIsostab->((s->a)->(b->t)->r)->rwithIsoaik=caseai(ExchangeidIdentity)ofExchangesabt->ksa(runIdentity#.bt){-# INLINE withIso #-}classWrappedswheretypeUnwrappeds::*_Wrapped'::Iso's(Unwrappeds)classWrappeds=>Rewrapped(s::*)(t::*)class(Rewrappedst,Rewrappedts)=>Rewrappingstinstance(Rewrappedst,Rewrappedts)=>Rewrappingstinstance(t~Composef'g'a')=>Rewrapped(Composefga)tinstanceWrapped(Composefga)wheretypeUnwrapped(Composefga)=f(ga)_Wrapped'=isogetComposeCompose_Wrapping::Rewrappingst=>(Unwrappeds->s)->Isost(Unwrappeds)(Unwrappedt)_Wrapping_=_Wrapped{-# INLINE _Wrapping #-}_Wrapped::Rewrappingst=>Isost(Unwrappeds)(Unwrappedt)_Wrapped=withIso_Wrapped'$\sa_->withIso_Wrapped'$\_bt->isosabt{-# INLINE _Wrapped #-}
However, once I do that, compiling with GHC 8.2.1 no longer stack overflows!
$ /opt/ghc/8.2.1/bin/ghc -c -O Lens.hs$ /opt/ghc/8.2.1/bin/ghc -c -O Bug.hsBug.hs:6:46: error: • Found type wildcard ‘_’ standing for ‘a'’ Where: ‘a'’ is a rigid type variable bound by the inferred type of traverseCompose :: (a -> f b) -> g a -> f (h a') at Bug.hs:7:1-46 To use the inferred type, enable PartialTypeSignatures • In the type signature: traverseCompose :: (a -> f b) -> g a -> f (h _) |6 | traverseCompose :: (a -> f b) -> g a -> f (h _) | ^Bug.hs:7:19: error: • Occurs check: cannot construct the infinite type: a ~ g'1 a Expected type: (f'0 a -> f (f'0 b)) -> Compose f'0 g'1 a -> f (h a') Actual type: (Unwrapped (Compose f'0 g'1 a) -> f (Unwrapped (h a'))) -> Compose f'0 g'1 a -> f (h a') • In the first argument of ‘(.)’, namely ‘_Wrapping Compose’ In the expression: _Wrapping Compose . traverse In an equation for ‘traverseCompose’: traverseCompose = _Wrapping Compose . traverse • Relevant bindings include traverseCompose :: (a -> f b) -> g a -> f (h a') (bound at Bug.hs:7:1) |7 | traverseCompose = _Wrapping Compose . traverse | ^^^^^^^^^^^^^^^^^Bug.hs:7:19: error: • Couldn't match type ‘g’ with ‘Compose f'0 g'1’ ‘g’ is a rigid type variable bound by the inferred type of traverseCompose :: (a -> f b) -> g a -> f (h a') at Bug.hs:7:1-46 Expected type: (a -> f b) -> g a -> f (h a') Actual type: (a -> f b) -> Compose f'0 g'1 a -> f (h a') • In the expression: _Wrapping Compose . traverse In an equation for ‘traverseCompose’: traverseCompose = _Wrapping Compose . traverse • Relevant bindings include traverseCompose :: (a -> f b) -> g a -> f (h a') (bound at Bug.hs:7:1) |7 | traverseCompose = _Wrapping Compose . traverse | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
So for some reason, this bug only seems to pop up when lens is installed as a library. I'm stumped.
$ /opt/ghc/8.2.1/bin/ghci Bug.hsGHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for helpLoaded GHCi configuration from /home/rgscott/.ghci[1 of 2] Compiling Lens ( Lens.hs, interpreted )[2 of 2] Compiling Bug ( Bug.hs, interpreted )Bug.hs:7:19: error: • Reduction stack overflow; size = 201 When simplifying the following type: g ~ Compose f'0 g'0 Use -freduction-depth=0 to disable this check (any upper bound you could choose might fail unpredictably with minor updates to GHC, so disabling the check is recommended if you're sure that type checking should terminate) • In the expression: _Wrapping Compose . traverse In an equation for ‘traverseCompose’: traverseCompose = _Wrapping Compose . traverse |7 | traverseCompose = _Wrapping Compose . traverse | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
So now for the magic question: what fixed this in HEAD?