[GHC] #13822: GHC not using injectivity?

#13822: GHC not using injectivity? -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple InjectiveFamilies, TypeInType | Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- This may be normal behavior but.. (Example from [http://repository.brynmawr.edu/cgi/viewcontent.cgi?article=1014&context=compsci_pubs System FC with Explicit Kind Equality]) {{{#!hs {-# LANGUAGE GADTs, TypeOperators, PolyKinds, DataKinds, TypeFamilyDependencies, TypeInType, RankNTypes, LambdaCase, EmptyCase #-} import Data.Kind data KIND = STAR | KIND :> KIND data Ty :: KIND -> Type where TInt :: Ty STAR TBool :: Ty STAR TMaybe :: Ty (STAR :> STAR) TApp :: Ty (a :> b) -> (Ty a -> Ty b) type family IK (k :: KIND) = (res :: Type) | res -> k where IK STAR = Type IK (a:>b) = IK a -> IK b type family I (t :: Ty k) = (res :: IK k) | res -> t where I TInt = Int I TBool = Bool I TMaybe = Maybe I (TApp f a) = (I f) (I a) data TyRep (k :: KIND) (t :: Ty k) where TyInt :: TyRep STAR TInt TyBool :: TyRep STAR TBool TyMaybe :: TyRep (STAR:>STAR) TMaybe TyApp :: TyRep (a:>b) f -> TyRep a x -> TyRep b (TApp f x) zero :: TyRep STAR a -> I a zero = \case TyInt -> 0 TyBool -> False TyApp TyMaybe _ -> Nothing }}} When I ask it to infer the representation for `Int` and `Bool` it does so with no surprises {{{#!hs -- Inferred type: -- -- int :: TyRep STAR TInt -> Int int rep = zero rep :: Int -- bool:: TyRep STAR TBool -> Bool bool rep = zero rep :: Bool }}} but inferring the representation for `Maybe Int` fails {{{#!hs -- v.hs:43:16: error: -- • Couldn't match kind ‘k’ with ‘'STAR’ -- ‘k’ is a rigid type variable bound by -- the inferred type of -- maybeInt :: (I 'TInt ~ Int, I 'TMaybe ~ Maybe) => -- TyRep 'STAR ('TApp 'TMaybe 'TInt) -> Maybe Int -- at v.hs:25:3 -- When matching the kind of ‘'TMaybe’ -- Expected type: Maybe Int -- Actual type: I ('TApp 'TMaybe 'TInt) -- • In the expression: zero rep :: Maybe Int -- In an equation for ‘maybeInt’: maybeInt rep = zero rep :: Maybe Int -- • Relevant bindings include -- rep :: TyRep 'STAR ('TApp 'TMaybe 'TInt) (bound at v.hs:43:10) -- maybeInt :: TyRep 'STAR ('TApp 'TMaybe 'TInt) -> Maybe Int -- (bound at v.hs:43:1) -- Failed, modules loaded: none. maybeInt rep = zero rep :: Maybe Int }}} even though `I` is injective and GHC knows that `I (TMaybe `TApp` TMaybe) = Maybe Int` {{{
:kind! I (TMaybe `TApp` TInt) I (TMaybe `TApp` TInt) :: IK 'STAR = Maybe Int }}}
-- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13822 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13822: GHC not using injectivity? -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | InjectiveFamilies, TypeInType 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 Iceland_jack): Output I do not understand, with explicit kinds / coercions {{{ /tmp/v.hs:41:16: error: • Couldn't match kind ‘k’ with ‘'STAR’ ‘k’ is a rigid type variable bound by the inferred type of maybeInt :: ((I 'STAR ('TInt |> Sym (Ty U(hole:{a2uB}, k1, 'STAR)_N)_N) :: IK * 'STAR) ~~ ((Int |> Sym Main.D:R:IK[0]) :: IK * 'STAR), (I ('STAR ':> 'STAR) ('TMaybe |> Sym (Ty (U(hole:{a2uB}, k1, 'STAR)_N ':> U(hole:{a2uC}, k, 'STAR)_N)_N)_N) :: IK * ('STAR ':> 'STAR)) ~~ ((Maybe |> Sym (Main.D:R:IK[1] <'STAR>_N <'STAR>_N ; Sym (Sym Main.D:R:IK[0] -> Sym Main.D:R:IK[0]))) :: IK * ('STAR ':> 'STAR))) => TyRep 'STAR ('TApp 'STAR 'STAR ('TMaybe |> Sym (Ty (U(hole:{a2uB}, k1, 'STAR)_N ':> U(hole:{a2uC}, k, 'STAR)_N)_N)_N) ('TInt |> Sym (Ty U(hole:{a2uB}, k1, 'STAR)_N)_N)) -> Maybe Int at /tmp/v.hs:23:3 When matching types ('TMaybe |> Sym (Ty (U(hole:{a2uB}, k1, 'STAR)_N ':> U(hole:{a2uC}, k, 'STAR)_N)_N)_N) :: Ty (k1 ':> k) 'TMaybe :: Ty ('STAR ':> 'STAR) Expected type: Maybe Int Actual type: (I 'STAR ('TApp 'STAR 'STAR ('TMaybe |> Sym (Ty (U(hole:{a2uB}, k1, 'STAR)_N ':> U(hole:{a2uC}, k, 'STAR)_N)_N)_N) ('TInt |> Sym (Ty U(hole:{a2uB}, k1, 'STAR)_N)_N)) |> Main.D:R:IK[0]) • In the expression: zero rep :: Maybe Int In an equation for ‘maybeInt’: maybeInt rep = zero rep :: Maybe Int • Relevant bindings include rep :: TyRep 'STAR ('TApp 'STAR 'STAR ('TMaybe |> Sym (Ty (U(hole:{a2uB}, k1, 'STAR)_N ':> U(hole:{a2uC}, k, 'STAR)_N)_N)_N) ('TInt |> Sym (Ty U(hole:{a2uB}, k1, 'STAR)_N)_N)) (bound at /tmp/v.hs:41:10) maybeInt :: TyRep 'STAR ('TApp 'STAR 'STAR ('TMaybe |> Sym (Ty (U(hole:{a2uB}, k1, 'STAR)_N ':> U(hole:{a2uC}, k, 'STAR)_N)_N)_N) ('TInt |> Sym (Ty U(hole:{a2uB}, k1, 'STAR)_N)_N)) -> Maybe Int (bound at /tmp/v.hs:41:1) Failed, modules loaded: none. }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13822#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13822: GHC not using injectivity? -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: | InjectiveFamilies, TypeInType Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by Iceland_jack): * status: new => closed * resolution: => fixed Comment: Never mind, this works in 8.3 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13822#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13822: GHC not using injectivity? -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: | InjectiveFamilies, TypeInType 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): Yes, I suspect that this is a slightly more involved version of #11348. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13822#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13822: GHC not using injectivity? -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: | InjectiveFamilies, TypeInType 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 simonpj): Would someone like to add it as a regression test? It never does any harm! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13822#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13822: GHC not using injectivity? -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: | InjectiveFamilies, TypeInType Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | typecheck/should_compile/T13822 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * testcase: => typecheck/should_compile/T13822 * milestone: => 8.2.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13822#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13822: GHC not using injectivity?
-------------------------------------+-------------------------------------
Reporter: Iceland_jack | Owner: (none)
Type: bug | Status: closed
Priority: normal | Milestone: 8.2.1
Component: Compiler | Version: 8.0.1
Resolution: fixed | Keywords:
| InjectiveFamilies, TypeInType
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
| typecheck/should_compile/T13822
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari
participants (1)
-
GHC