[GHC] #10188: prefix type-level cons can't be parsed

#10188: prefix type-level cons can't be parsed -------------------------------------+------------------------------------- Reporter: Kinokkory | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: GHC rejects Unknown/Multiple | valid program Test Case: | Blocked By: Blocking: | Related Tickets: Differential Revisions: | -------------------------------------+------------------------------------- Whereas other type operators (whether used as type families or used as data constructors) can be safely used in a prefix form, only the type- level cons of the built-in list kind can't be used in a prefix form. It really is a problem because we don't have any means to express type- level cons itself in source code. This for example prevents us from writing a generic type-level foldr that takes the built-in list and other similar data types alike. In a ghci: {{{#!hs
:set -XDataKinds -XTypeOperators data Listy a = a ::: Listy a :kind! (:::) (:::) :: k -> Listy k -> Listy k = forall (k :: BOX). (':::) :kind! (:)
<interactive>:1:2: parse error on input ‘:’ }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10188 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10188: prefix type-level cons can't be parsed -------------------------------------+------------------------------------- Reporter: Kinokkory | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by simonpj): Good point. This is just a question of fixing the parser. Would anyone like to have a go? Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10188#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10188: prefix type-level cons can't be parsed -------------------------------------+------------------------------------- Reporter: Kinokkory | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 (Parser) | Keywords: Resolution: | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: GHC rejects | Test Case: valid program | Blocking: Blocked By: | Differential Revisions: Related Tickets: | -------------------------------------+------------------------------------- Changes (by thomie): * component: Compiler => Compiler (Parser) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10188#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10188: prefix type-level cons can't be parsed -------------------------------------+------------------------------------- Reporter: Kinokkory | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 (Parser) | Keywords: Resolution: | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: GHC rejects | Test Case: valid program | Blocking: Blocked By: | Differential Revisions: Related Tickets: | -------------------------------------+------------------------------------- Description changed by Kinokkory: Old description:
Whereas other type operators (whether used as type families or used as data constructors) can be safely used in a prefix form, only the type- level cons of the built-in list kind can't be used in a prefix form.
It really is a problem because we don't have any means to express type- level cons itself in source code. This for example prevents us from writing a generic type-level foldr that takes the built-in list and other similar data types alike.
In a ghci:
{{{#!hs
:set -XDataKinds -XTypeOperators data Listy a = a ::: Listy a :kind! (:::) (:::) :: k -> Listy k -> Listy k = forall (k :: BOX). (':::) :kind! (:)
<interactive>:1:2: parse error on input ‘:’ }}}
New description: Whereas other type operators (whether used as type families or used as data constructors) can be safely used in a prefix form, only the type- level cons of the built-in list kind can't be used in a prefix form. It really is a problem because we don't have any means to express the type-level cons itself in source code. This for example prevents us from writing a generic type-level foldr that takes the built-in list and other similar data types alike. In a ghci: {{{#!hs
:set -XDataKinds -XTypeOperators data Listy a = a ::: Listy a | Nily :kind! (:::) (:::) :: k -> Listy k -> Listy k = forall (k :: BOX). (':::) :kind! (:)
<interactive>:1:2: parse error on input ‘:’ }}} -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10188#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10188: prefix type-level cons can't be parsed -------------------------------------+------------------------------------- Reporter: Kinokkory | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 (Parser) | Keywords: Resolution: | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: GHC rejects | Test Case: valid program | Blocking: Blocked By: | Differential Revisions: Related Tickets: | -------------------------------------+------------------------------------- Comment (by goldfire): It's unfortunate (and a bug) that the code you wrote doesn't work, but there is support for the feature you want: {{{
:kind '(:) '(:) :: k -> [k] -> [k] }}}
Note the `'`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10188#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10188: prefix type-level cons can't be parsed -------------------------------------+------------------------------------- Reporter: Kinokkory | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 (Parser) | Keywords: Resolution: | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: GHC rejects | Test Case: valid program | Blocking: Blocked By: | Differential Revisions: Related Tickets: | -------------------------------------+------------------------------------- Comment (by Kinokkory): Oh, I didn't know that. Thanks a lot! In a ghci: {{{#!hs
:kind! '(:::) '(:::) :: k -> Listy k -> Listy k = forall (k :: BOX). (':::) :kind! (':::)
<interactive>:1:3: parse error on input ‘:::’
:kind! (':)
<interactive>:1:3: parse error on input ‘:’ }}} The message "forall (k :: BOX). (':::)" seems inconsistent with the parsing mechanism that allows "'(:::)" instead of (':::). I'll report this as another new bug! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10188#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10188: prefix type-level cons can't be parsed -------------------------------------+------------------------------------- Reporter: Kinokkory | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 (Parser) | Keywords: Resolution: | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: GHC rejects | Test Case: valid program | Blocking: Blocked By: | Differential Revisions: Related Tickets: #10189 | -------------------------------------+------------------------------------- Changes (by Kinokkory): * related: => #10189 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10188#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10188: prefix type-level cons can't be parsed -------------------------------------+------------------------------------- Reporter: Kinokkory | Owner: Kinokkory Type: bug | Status: new Priority: normal | Milestone: 7.12.1 Component: Compiler | Version: 7.8.4 (Parser) | Keywords: Resolution: | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: GHC rejects | Test Case: valid program | Blocking: Blocked By: | Differential Revisions: Related Tickets: #10189 | -------------------------------------+------------------------------------- Changes (by Kinokkory): * cc: Kinokkory (added) * owner: => Kinokkory * milestone: => 7.12.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10188#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10188: prefix type-level cons can't be parsed -------------------------------------+------------------------------------- Reporter: Kinokkory | Owner: Kinokkory Type: bug | Status: patch Priority: normal | Milestone: 7.12.1 Component: Compiler | Version: 7.8.4 (Parser) | Keywords: Resolution: | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: GHC rejects | Test Case: valid program | Blocking: Blocked By: | Differential Revisions: Phab:D768 Related Tickets: #10189 | -------------------------------------+------------------------------------- Changes (by Kinokkory): * status: new => patch * differential: => Phab:D768 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10188#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10188: prefix type-level cons can't be parsed -------------------------------------+------------------------------------- Reporter: Kinokkory | Owner: Kinokkory Type: bug | Status: patch Priority: normal | Milestone: 7.12.1 Component: Compiler | Version: 7.8.4 (Parser) | Keywords: Resolution: | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: GHC rejects | Test Case: valid program | Blocking: Blocked By: | Differential Revisions: Phab:D768 Related Tickets: #10189 | -------------------------------------+------------------------------------- Comment (by Kinokkory): This patch makes `(:) Int [Float, Double]` and `Int : [Float, Double]` parsed. In fact, infix type-level cons also used to be not parsed without `'`. Essentially, I changed the definition of `tyconsym` by adding `| ':' ...`. {{{ tyconsym :: { Located RdrName } : CONSYM { sL1 $1 $! mkUnqual tcClsName (getCONSYM $1) } | VARSYM { sL1 $1 $! mkUnqual tcClsName (getVARSYM $1) } | ':' { sL1 $1 $! consDataCon_RDR } | '*' { sL1 $1 $! mkUnqual tcClsName (fsLit "*") } | '-' { sL1 $1 $! mkUnqual tcClsName (fsLit "-") } }}} By the way I wonder what `| '*' ...` and `| '-' ...` are for. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10188#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10188: prefix type-level cons can't be parsed -------------------------------------+------------------------------------- Reporter: Kinokkory | Owner: Kinokkory Type: bug | Status: patch Priority: normal | Milestone: 7.12.1 Component: Compiler | Version: 7.8.4 (Parser) | Keywords: Resolution: | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: GHC rejects | Test Case: valid program | Blocking: Blocked By: | Differential Revisions: Phab:D768 Related Tickets: #10189 | -------------------------------------+------------------------------------- Comment (by goldfire): Looking more closely at this, I think this was not a bug in the parser, but in the pretty-printer. The pretty-printer prints type-level `:::` as `(':::)`, but it should be `'(:::)`, which is what is parsed. Normal type- level cons is parsed the same way, with the tick outside the parentheses. (Which I think is confusing, but that ship has sailed.) On the other hand, it does seem draconian to '''require''' the tick for cons, when `:` has no possible other interpretation as a type-level constant. So, considering this as a feature request, I think it's a good one. Thanks for the patch! Did you end up submitting a separate bug report for the pretty-printer? That's still outstanding, I believe. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10188#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10188: prefix type-level cons can't be parsed
-------------------------------------+-------------------------------------
Reporter: Kinokkory | Owner: Kinokkory
Type: bug | Status: patch
Priority: normal | Milestone: 7.12.1
Component: Compiler | Version: 7.8.4
(Parser) | Keywords:
Resolution: | Architecture:
Operating System: Unknown/Multiple | Unknown/Multiple
Type of failure: GHC rejects | Test Case:
valid program | Blocking:
Blocked By: | Differential Revisions: Phab:D768
Related Tickets: #10189 |
-------------------------------------+-------------------------------------
Comment (by Austin Seipp

#10188: prefix type-level cons can't be parsed -------------------------------------+------------------------------------- Reporter: Kinokkory | Owner: Kinokkory Type: bug | Status: closed Priority: normal | Milestone: 7.12.1 Component: Compiler | Version: 7.8.4 (Parser) | Keywords: Resolution: fixed | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: GHC rejects | Test Case: valid program | Blocking: Blocked By: | Differential Revisions: Phab:D768 Related Tickets: #10189 | -------------------------------------+------------------------------------- Changes (by Kinokkory): * status: patch => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10188#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC