[GHC] #11962: Support induction recursion

#11962: Support induction recursion -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 8.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Now that we have `-XTypeInType`, let's take it a step further and allow induction recursion. This feature exists in Agda and Idris. Here is a short example of what can be done in Agda: {{{ mutual -- Codes for types. data U : Set where nat : U pi : (a : U) → (El a → U) → U -- A function that interprets codes as actual types. El : U → Set El nat = ℕ El (pi a b) = (x : El a) → El (b x) }}} Note that the `U` datatype and the `El` function depend on each other. But if you look more closely, the header for `U` does not depend on `El`; only the constructors of `U` depend on `El`. So if we typecheck `U : Set` first, then `El : U → Set`, then the constructors of `U`, then the equations of `El`, we're OK. Translation into Haskell: {{{ import Data.Kind data family Sing (a :: k) -- we still require singletons data U :: Type where Nat :: U Pi :: Sing (a :: U) -> (El a -> U) -> U type family El (u :: U) :: Type where El 'Nat = Int El (Pi a b) = forall (x :: El a). Sing x -> El (b x) }}} This currently errors with {{{ • Type constructor ‘U’ cannot be used here (it is defined and used in the same recursive group) • In the kind ‘U’ }}} It needn't error. (I'm cheating a bit here, because for unrelated reasons, we can't return a `forall` on the right-hand side of a type family. But that's not the issue at hand.) I have some very sketchy notes on how we might do this [wiki:DependentHaskell/Internal#Separatingtypesignaturesfromdefinitions here]. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11962 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11962: Support induction recursion -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: 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 thomie): * cc: alexvieth (added) Comment: (@goldfire mentioned in ticket:11348#comment:17 that @alexvieth might be interested in working on this ticket, so I'm CC-ing him here) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11962#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11962: Support induction recursion -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: 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 skeuchel): * cc: skeuchel (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11962#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11962: Support induction recursion -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: 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 goldfire): * keywords: => TypeInType -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11962#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11962: Support induction recursion -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: 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): * cc: Iceland_jack (added) Comment: TODO Add GHC to [https://en.wikipedia.org/wiki/Induction-recursion#Usage Wikipedia] when implemented ;) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11962#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11962: Support induction recursion -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: 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 RyanGlScott): * cc: RyanGlScott (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11962#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11962: Support induction recursion -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: TypeInType Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #13901 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * related: => #13901 Comment: Replying to [ticket:11962 goldfire]:
(I'm cheating a bit here, because for unrelated reasons, we can't return a `forall` on the right-hand side of a type family. But that's not the issue at hand.)
I'm tracking this issue separately at #13901, since I would find that useful in its own right. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11962#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11962: Support induction recursion -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: TypeInType Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #13901 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by vagarenko): * cc: vagarenko (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11962#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11962: Support induction recursion -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: TypeInType Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 9269 | Blocking: Related Tickets: #13901 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by andrewthad): @goldfire To my understanding, the priority of this ticket is getting induction recursion supported for GADTs. I'm unclear on how the "same recursive subgroup" error in the example you gave is related to the "same recursive subgroup" error that I run into with typeclasses. For example: {{{ class Grounded v where type Rep (a :: v) :: RuntimeRep type Lifted (a :: v) :: Type type Unlifted (a :: v) :: TYPE (Rep a) ... some methods in here as well }}} This currently errors with: {{{ sorted_int_type.hs:100:35: error: • Type constructor ‘Rep’ cannot be used here (it is defined and used in the same recursive group) • In the first argument of ‘TYPE’, namely ‘(Rep a)’ In the kind ‘TYPE (Rep a)’ | 100 | type Unlifted (a :: v) :: TYPE (Rep a) | ^^^ }}} I have to split the class up: {{{ class GroundSuper v where type Rep (a :: v) :: RuntimeRep class GroundSuper v => Grounded v where type Lifted (a :: v) :: Type type Unlifted (a :: v) :: TYPE (Rep a) }}} It's not the worst thing ever, but it's kind of silly that what really is logically one typeclass needs to be split up into two typeclasses. It's not totally clear to me if this is really even the same issue as what you describe above or if fixing one automatically fixes the other, but it gives the same error message, which leads me to believe that they are somehow related. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11962#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11962: Support induction recursion -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: TypeInType Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 9269 | Blocking: Related Tickets: #13901 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): comment:9 is certainly related, but still separate from the eventual goal of this ticket. I do think a fix for this ticket would fix comment:9, but comment:9 could also be fixed independently (and, I believe, more easily). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11962#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11962: Support induction recursion -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: TypeInType Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 9269 | Blocking: Related Tickets: #12612, #13901 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * related: #13901 => #12612, #13901 Comment: andrewthad, that particular featurette is being tracked separately at #12612. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11962#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11962: Support induction recursion -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: TypeInType Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 9269 | Blocking: Related Tickets: #12612, #13901, | Differential Rev(s): #15942 | Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * related: #12612, #13901 => #12612, #13901, #15942 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11962#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11962: Support induction recursion -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: TypeInType Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: 9269 | Blocking: Related Tickets: #12612, #13901, | Differential Rev(s): #15942 | Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): We think that implementing #12088, comment:37 will nail this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11962#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC