[GHC] #15658: strange inferred kind with TypeInType

#15658: strange inferred kind with TypeInType -------------------------------------+------------------------------------- Reporter: dmwit | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.2 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: -------------------------------------+------------------------------------- This type family has a strange kind to begin with: {{{ {-# Language TypeFamilies , TypeInType #-} type family F f a :: a }}} But it gets even stranger when you ask ghci what it thinks about F: {{{
:k F F :: * -> forall a -> a }}}
There is a forall which doesn't seem to bind any variables and hasn't got the customary delimiting dot. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15658 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15658: strange inferred kind with TypeInType -------------------------------------+------------------------------------- Reporter: dmwit | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.2 Resolution: | Keywords: TypeInType, | GHCProposal 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): * keywords: => TypeInType, GHCProposal Comment: This is expected: `TypeInType` gives programmers a limited ability to write dependent quantification in kinds. The [https://downloads.haskell.org/~ghc/8.4.3/docs/html/users_guide/glasgow_exts.... #inferring-dependency-in-datatype-declarations Inferring dependency in datatype declarations] section of the users' guide documents this feature to some degree. The part that is not documented is the `forall k ->` bit, which I'll briefly explain here. Here is the type family you wrote (with explicit kinds for clarity): {{{#!hs type family F (f :: *) (a :: *) :: a }}} This binds the `f` and `a` type variables, and interestingly enough, it //reuses// the bound `a` type variable later in the return kind. In other words, `a` is used in a dependent fashion, so the kind for `F` is (again, with explicit kinds for clarity): {{{#!hs F :: * -> forall (a :: *) -> a }}} This kind says that `F` takes two type arguments of kind `*` and returns a type of kind `a`, where `a` is the second type argument. Importantly, the kind of `F` is //not// `* -> forall (a :: *). a`, since that would imply that `a` is insivible (i.e., that you don't explicitly pass it as an argument to `F`). You can think of the use of `->` versus `.` as indicating visible arguments versus invisible ones. As I briefly mentioned before, this aspect of kinds is not really documented at the moment. This is partly because while you can observe these kinds in GHCi (through `:kind`), you cannot write them yourself (they'll simply fail to parse at the moment). [https://github.com/ghc- proposals/ghc-proposals/pull/81 This GHC proposal] aims to rectify this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15658#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15658: strange inferred kind with TypeInType -------------------------------------+------------------------------------- Reporter: dmwit | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.2 Resolution: | Keywords: TypeInType, | GHCProposal 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 dmwit): I agree: it should be documented with some care. Here is another case worth discussing when writing the documentation. If I try to follow your reasoning for a modified type family, say: {{{ type family G a :: a }}} I reason that it should be: {{{ G :: forall (a :: *) -> a }}} So without the explicit kinding, I would expect ghci to give `G` the kind `forall a -> a`. But ghci does not agree: {{{
:k G G :: a }}}
-- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15658#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15658: strange inferred kind with TypeInType -------------------------------------+------------------------------------- Reporter: dmwit | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.2 Resolution: | Keywords: TypeInType, | GHCProposal 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): Replying to [comment:2 dmwit]:
So without the explicit kinding, I would expect ghci to give `G` the kind `forall a -> a`. But ghci does not agree:
{{{
:k G G :: a }}}
That's due to a separate GHC bug, #14238, which has been fixed in GHC 8.6.1. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15658#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15658: strange inferred kind with TypeInType -------------------------------------+------------------------------------- Reporter: dmwit | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: 8.10.1 Component: Compiler | Version: 8.4.2 Resolution: | Keywords: TypeInType, | GHCProposal Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #16326 | Differential Rev(s): Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/378 -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => https://gitlab.haskell.org/ghc/ghc/merge_requests/378 * related: => #16326 * milestone: 8.6.1 => 8.10.1 Comment: https://gitlab.haskell.org/ghc/ghc/merge_requests/378 implements the ability to write this in the source syntax (and documents it in the users' guide). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15658#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15658: strange inferred kind with TypeInType -------------------------------------+------------------------------------- Reporter: dmwit | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: 8.10.1 Component: Compiler | Version: 8.4.2 Resolution: | Keywords: TypeInType, | GHCProposal, | VisibleDependentQuantification Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #16326 | Differential Rev(s): Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/378 -------------------------------------+------------------------------------- Changes (by RyanGlScott): * keywords: TypeInType, GHCProposal => TypeInType, GHCProposal, VisibleDependentQuantification -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15658#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15658: strange inferred kind with TypeInType -------------------------------------+------------------------------------- Reporter: dmwit | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.10.1 Component: Compiler | Version: 8.4.2 Resolution: fixed | Keywords: TypeInType, | GHCProposal, | VisibleDependentQuantification Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #16326 | Differential Rev(s): Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/378 -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: patch => closed * resolution: => fixed Comment: Landed in [https://gitlab.haskell.org/ghc/ghc/commit/c26d299dc422f43b8c37da4b26da2067ee... c26d299dc422f43b8c37da4b26da2067eedcbae8]. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15658#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15658: strange inferred kind with TypeInType -------------------------------------+------------------------------------- Reporter: dmwit | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.10.1 Component: Compiler | Version: 8.4.2 Resolution: fixed | Keywords: TypeInType, | GHCProposal, | VisibleDependentQuantification Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #16326 | Differential Rev(s): Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/378 -------------------------------------+------------------------------------- Comment (by simonpj): Should we have a regression test here? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15658#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15658: strange inferred kind with TypeInType -------------------------------------+------------------------------------- Reporter: dmwit | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.10.1 Component: Compiler | Version: 8.4.2 Resolution: fixed | Keywords: TypeInType, | GHCProposal, | VisibleDependentQuantification Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #16326 | Differential Rev(s): Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/378 -------------------------------------+------------------------------------- Comment (by RyanGlScott): No. This ticket is specifically about the users' guide. #16326 tracks the actual implementation side of things, and makes mention of the relevant regression tests. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15658#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15658: strange inferred kind with TypeInType
-------------------------------------+-------------------------------------
Reporter: dmwit | Owner: (none)
Type: bug | Status: closed
Priority: normal | Milestone: 8.10.1
Component: Compiler | Version: 8.4.2
Resolution: fixed | Keywords: TypeInType,
| GHCProposal,
| VisibleDependentQuantification
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: #16326 | Differential Rev(s):
Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/378
-------------------------------------+-------------------------------------
Comment (by Marge Bot
participants (1)
-
GHC