[GHC] #13795: :kind! is not expanding type synonyms anymore

#13795: :kind! is not expanding type synonyms anymore --------------------------------------+--------------------------------- Reporter: Hjulle | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Keywords: | Operating System: Linux Architecture: x86_64 (amd64) | Type of failure: None/Unknown Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: --------------------------------------+--------------------------------- Given {{{#!hs type A = () :kind! A }}} Expected result: {{{#!hs A :: * = () }}} Actual result: {{{#!hs A :: * = A }}} ---- Some IRC conversation on the topic (on #ghc): {{{ 23:37 < hjulle> :kind! does not seem to expand type synonyms for me (in GHC 8.0.2), it just prints them verbatim. Does anyone else have this problem? Example: "type A = ()" ":kind! A" will print out "A :: * = A" (which is not very helpful). 23:40 < hjulle> Is this a bug? The documentation (https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ghci.html #ghci-cmd-:kind) explicitly states that :kind! should expand type synonyms, so I think yes? 23:57 < RyanGlScott> hjulle: That's absolute a bug. File a ticket! 23:57 < RyanGlScott> *absolutely 23:58 < RyanGlScott> Moreover, I know why that's happening 23:59 < RyanGlScott> Internally, :kind! uses the normalise_type function to reduce type families: http://git.haskell.org/ghc.git/blob/e77b9a2069bca9018f989d7c4f54da099e3ab215... 23:59 < RyanGlScott> But see the comment there Day changed to 07 jun 2017 00:00 < RyanGlScott> -- Try to not to disturb type synonyms if possible 00:01 < RyanGlScott> So fixing this would just be a matter of calling coreView afterwards (which expands type synonyms) 00:02 < RyanGlScott> er, actually, expandTypeSynonyms is even better: http://git.haskell.org/ghc.git/blob/e77b9a2069bca9018f989d7c4f54da099e3ab215... }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13795 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13795: :kind! is not expanding type synonyms anymore -------------------------------------+------------------------------------- Reporter: Hjulle | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.0.2 Resolution: | Keywords: newcomer 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: => newcomer * component: Compiler => GHCi * os: Linux => Unknown/Multiple * architecture: x86_64 (amd64) => Unknown/Multiple -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13795#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13795: :kind! is not expanding type synonyms anymore -------------------------------------+------------------------------------- Reporter: Hjulle | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.0.2 Resolution: | Keywords: newcomer 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): Did `:kind!` ever expand synonyms? The user manual claims that it does, but I can see no evidence that it ever did. Do we want it to expand synonyms? I think probably yes. If so, the right spot is here in `TcRnDriver`: {{{ ; ty' <- if normalise then do { fam_envs <- tcGetFamInstEnvs ; let (_, ty') = normaliseType fam_envs Nominal ty ; return ty' } else return ty ; }}} After calling `normaliseType`, call `Type.expandTypeSynonyms`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13795#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13795: :kind! is not expanding type synonyms anymore -------------------------------------+------------------------------------- Reporter: Hjulle | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.0.2 Resolution: | Keywords: newcomer 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 simonpj]:
Did `:kind!` ever expand synonyms?
The user manual claims that it does, but I can see no evidence that it ever did.
It did in GHC 7.8.4: {{{ 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. λ> type A = () λ> :kind! A A :: * = () }}} But not in GHC 7.10.3: {{{ GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help λ> type A = Bool λ> :kind! A A :: * = A }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13795#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13795: :kind! is not expanding type synonyms anymore -------------------------------------+------------------------------------- Reporter: Hjulle | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.0.2 Resolution: | Keywords: newcomer 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 goldfire): IIRC, this was a deliberate choice: the idea was that type families are best understood after expansion but type synonyms are best understood without expanding. The process used in `:kind!` even looks through type synonyms to see if there are more type family reductions possible. This is all a matter of taste. We ''could'' change it (easily). Would it surprise other users? Perhaps. This is something wider community input might help to enlighten, but a full ghc-proposal seems rather heavy. I don't know of a lighter-weight way forward, though. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13795#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13795: :kind! is not expanding type synonyms anymore -------------------------------------+------------------------------------- Reporter: Hjulle | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.0.2 Resolution: | Keywords: newcomer 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 Hjulle): I found this when I was looking for a way to expand type signatures. According to https://stackoverflow.com/questions/13595773/expand-type- synonyms-type-families-with-ghci :kind! is the way to do it. If it was intentional to remove that, is there another way to expand type signatures in ghci? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13795#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13795: :kind! is not expanding type synonyms anymore -------------------------------------+------------------------------------- Reporter: Hjulle | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.0.2 Resolution: | Keywords: newcomer 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): We could offer some way to get * No processing of the type (currently `:kind`) * Type families evaluated (currently `:kind!`) * Type families evaluated and type synonyms expanded (`:kind!!` perhaps?) And, I suppose, the fourth possibility (expand type synonyms but do not evaluate type families). But that's probably over-complicated -- few users would care. If we are going to have only two possibilities (`:k` and `:k!`), what the user manual says makes most sense: `:kind!` evaluates everything, type families, type synonyms and all. I suppose we could have a `:set -XNoExpandSynonymsOnBang` flag or something. Implementation is easy. The hard thing to know is what users want. Users, speak up! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13795#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13795: :kind! is not expanding type synonyms anymore -------------------------------------+------------------------------------- Reporter: Hjulle | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.0.2 Resolution: | Keywords: newcomer 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 vl.still): I found a possible workaround (usable more with appropriate HINT or GHC API functions such as Language.Haskell.Interpreter.normalizeType) and inconsistency in behavior of current GHC(i) (8.0.2): Let's have following type family: {{{#!hs type family Id a type instance Id a = a }}} now in GHCi: {{{
λ= :kind! String String :: * = String
λ= :kind! Id String Id String :: * = [Char]
λ= :kind! Id String -> String Id String -> String :: * = [Char] -> String }}}
So it seems that type synonyms are expanded as long as they are in subexpression of an expression with type family. I personally would appriciate in :kind! expanded type synonyms as well as type families. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13795#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13795: :kind! is not expanding type synonyms anymore -------------------------------------+------------------------------------- Reporter: Hjulle | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.0.2 Resolution: | Keywords: newcomer 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 alpmestan): I went ahead and implemented Simon's first suggestion (quick and dirty way), as this is what I would personally want to have, I think. The patch is indeed very, very small: https://gist.github.com/alpmestan/50a0a00ebf4208c8ae898f84d6b41e07 Would people be happy with this patch (modulo nicer formatting and possible review feedback)? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13795#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13795: :kind! is not expanding type synonyms anymore -------------------------------------+------------------------------------- Reporter: Hjulle | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.0.2 Resolution: | Keywords: newcomer 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 alpmestan): * cc: alpmestan (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13795#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13795: :kind! is not expanding type synonyms anymore -------------------------------------+------------------------------------- Reporter: Hjulle | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.0.2 Resolution: | Keywords: newcomer 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 goldfire): The patch looks reasonable to me. But I do think this should go via the normal [https://github.com/ghc-proposals/ghc-proposals ghc-proposals] process, as it's a user-facing feature. I know this is small, but I've found that process to be a great way to refine a feature to a beautiful final form. No doubt several "small" features I've added (e.g., the `:type +d` syntax) would have benefited from such a process. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13795#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13795: :kind! is not expanding type synonyms anymore -------------------------------------+------------------------------------- Reporter: Hjulle | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.0.2 Resolution: | Keywords: newcomer 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 alpmestan): No problem, I'll go through that process then, thanks! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13795#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13795: :kind! is not expanding type synonyms anymore -------------------------------------+------------------------------------- Reporter: Hjulle | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.0.2 Resolution: | Keywords: newcomer 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 alpmestan): There's a proposal up [https://github.com/ghc-proposals/ghc- proposals/pull/79 on github]. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13795#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC