Opened 3 years ago
Closed 3 years ago
#10931 closed bug (fixed)
layers-0.1 does not compile with ghc-7.10 (likely a regression from ghc-7.8)
Reported by: | slyfox | Owned by: | |
---|---|---|---|
Priority: | normal | Milestone: | 8.0.1 |
Component: | Compiler (Type checker) | Version: | 7.10.2 |
Keywords: | Cc: | simonpj, goldfire | |
Operating System: | Unknown/Multiple | Architecture: | Unknown/Multiple |
Type of failure: | GHC rejects valid program | Test Case: | indexed-types/should_compile/T10931 |
Blocked By: | Blocking: | ||
Related Tickets: | Differential Rev(s): | ||
Wiki Page: |
Description
Distilled example is the following:
{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE AllowAmbiguousTypes #-} -- not needed for 7.8, should not be needed for 7.10 as well {-# OPTIONS_GHC -Wall #-} module L () where import Prelude () -- clean up data IdT f a = IdC (f a) class ( m ~ Outer m (Inner m) ) => BugC (m :: * -> *) where type Inner m :: * -> * type Outer m :: (* -> *) -> * -> * bug :: ( forall n. ( n ~ Outer n (Inner n) , Outer n ~ Outer m ) => Inner n a) -> m a instance BugC (IdT m) where type Inner (IdT m) = m type Outer (IdT m) = IdT bug f = IdC f
ghc-7.8 compiles the sample just fine:
$ ghci a.hs GHCi, version 7.8.4: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling L ( a.hs, interpreted ) Ok, modules loaded: L. *L> :t bug bug :: (BugC (t1 t), Outer (t1 t) ~ t1, Inner (t1 t) ~ t) => (forall (n :: * -> *). (n ~ Outer n (Inner n), Outer n ~ Outer (t1 t)) => Inner n a) -> t1 t a
ghc-7.10 can't build it even with AllowAmbiguousTypes
$ ghci a.hs GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling L ( a.hs, interpreted ) a.hs:28:17: Couldn't match type ‘m’ with ‘Inner (IdT m)’ ‘m’ is a rigid type variable bound by the instance declaration at a.hs:24:10 Expected type: Outer (IdT m) (Inner (IdT m)) Actual type: IdT m Relevant bindings include f :: forall (n :: * -> *). (n ~ Outer n (Inner n), Outer n ~ Outer (IdT m)) => Inner n a (bound at a.hs:28:9) bug :: (forall (n :: * -> *). (n ~ Outer n (Inner n), Outer n ~ Outer (IdT m)) => Inner n a) -> IdT m a (bound at a.hs:28:5) In the first argument of ‘IdC’, namely ‘f’ In the expression: IdC f In an equation for ‘bug’: bug f = IdC f Failed, modules loaded: none.
Without AllowAmbiguousTypes the error gives a hint on ambiguity (which does not really exist as I understand associated type families):
$ ghci a-no-ambig-language.hs GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling L ( a.hs, interpreted ) a.hs:28:17: Couldn't match type ‘m’ with ‘Inner (IdT m)’ ‘m’ is a rigid type variable bound by the instance declaration at a.hs:24:10 Expected type: Outer (IdT m) (Inner (IdT m)) Actual type: IdT m Relevant bindings include f :: forall (n :: * -> *). (n ~ Outer n (Inner n), Outer n ~ Outer (IdT m)) => Inner n a (bound at a.hs:28:9) bug :: (forall (n :: * -> *). (n ~ Outer n (Inner n), Outer n ~ Outer (IdT m)) => Inner n a) -> IdT m a (bound at a.hs:28:5) In the first argument of ‘IdC’, namely ‘f’ In the expression: IdC f In an equation for ‘bug’: bug f = IdC f Failed, modules loaded: none.
It seems that ghc-7.8 is more correct here.
Thanks!
Change History (8)
comment:1 Changed 3 years ago by
comment:2 Changed 3 years ago by
Oh that's good! ghc-7.10 branch doesn't work though. I wonder when it was fixed.
$ inplace/bin/ghc-stage2 --interactive T10931.hs GHCi, version 7.10.2.20151003: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling L ( T10931.hs, interpreted ) T10931.hs:28:17: Couldn't match type ‘m’ with ‘Inner (IdT m)’ ‘m’ is a rigid type variable bound by the instance declaration at T10931.hs:24:10 Expected type: Outer (IdT m) (Inner (IdT m)) Actual type: IdT m Relevant bindings include f :: forall (n :: * -> *). (n ~ Outer n (Inner n), Outer n ~ Outer (IdT m)) => Inner n a (bound at T10931.hs:28:9) bug :: (forall (n :: * -> *). (n ~ Outer n (Inner n), Outer n ~ Outer (IdT m)) => Inner n a) -> IdT m a (bound at T10931.hs:28:5) In the first argument of ‘IdC’, namely ‘f’ In the expression: IdC f In an equation for ‘bug’: bug f = IdC f Failed, modules loaded: none.
comment:3 follow-up: 5 Changed 3 years ago by
Cc: | goldfire added |
---|
Thanks for a small test case. I've added a test so if this goes wrong again we'll know.
I have not investigated in detail. Would someone like to git-bisect to find when it got fixed? I have a horrid feeling that it'll just be part of some fairly substantial change to the type constraint solver, which we won't want to merge en-masse to 7.10.3.
As things stand, it's a bug in 7.10 that we don't know how to fix. I'm sure we could find out, but it'd take precious cycles.
How bad is it if this library doesn't work? I imagine this is relatively rare else it'd show up more often.
Richard; you might be interested.
comment:4 Changed 3 years ago by
comment:5 follow-up: 7 Changed 3 years ago by
Replying to simonpj:
How bad is it if this library doesn't work? I imagine this is relatively rare else it'd show up more often.
Nonworking library in 7.10 is absolutely not a problem for me.
comment:7 Changed 3 years ago by
Milestone: | → 8.0.1 |
---|---|
Test Case: | → indexed-types/should_compile/T10931 |
comment:8 Changed 3 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
Works fine with HEAD (ghc-7.11.20150921), also without
AllowAmbiguousTypes
.