[GHC] #10193: TypeRep Show instance doesn't add parens around type operators

#10193: TypeRep Show instance doesn't add parens around type operators -------------------------------------+------------------------------------- Reporter: | Owner: pawel.nowak | Status: new Type: bug | Milestone: Priority: normal | Version: 7.10.1-rc3 Component: | Operating System: Unknown/Multiple libraries/base | Type of failure: Incorrect result Keywords: | at runtime Architecture: | Blocked By: Unknown/Multiple | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- The following code {{{#!hs {-# LANGUAGE AutoDeriveTypeable #-} {-# LANGUAGE TypeOperators #-} import Data.Typeable data a :*: b = Pair a b main = print (typeOf (Pair 'a' 'b')) }}} prints {{{#!hs :*: Char Char }}} which is not valid Haskell. I belive it should print {{{#!hs (:*:) Char Char }}} In my particular case I am using Hint to interpret a type involving type operators. Hint uses showed TypeRep as a type annotation: {{{#!hs let type_str = show $ Data.Typeable.typeOf wit ... let expr_typesig = concat [parens e, " :: ", type_str] }}} What results in a parse error. I can write a patch if someone confirms that's the desired behavior and doesn't break anything. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10193 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10193: TypeRep Show instance doesn't add parens around type operators -------------------------------------+------------------------------------- Reporter: pawel.nowak | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.12.1 Component: libraries/base | Version: 7.10.1-rc3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by thomie): * milestone: => 7.12.1 Comment: Fwiw, GHCi does the right thing already: {{{
:t Pair 'a' 'b' Pair 'a' 'b' :: Char :*: Char }}}
-- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10193#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10193: TypeRep Show instance doesn't add parens around type operators -------------------------------------+------------------------------------- Reporter: pawel.nowak | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.12.1 Component: libraries/base | Version: 7.10.1-rc3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by pawel.nowak): Replying to [comment:1 thomie]:
Fwiw, GHCi does the right thing already: Yes, but I think it works on GHC's internal Type, not on Typeable's TypeRep. \\
After some more thought, it would be useful to have an instance that prints a valid Haskell type, that is: * Parens around operators, * Fully qualified types, * No kinds - right now a TypeRep of e.g. "V 5" from Linear.V is printed as "V Nat 5". I'll implement that in Hint for now, but it would be nice to have that in Data.Typeable, possibly as an alternative to the current show instance. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10193#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10193: TypeRep Show instance doesn't add parens around type operators -------------------------------------+------------------------------------- Reporter: pawel.nowak | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.12.1 Component: libraries/base | Version: 7.10.1-rc3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by simonpj): A better `Show` instance for `TypeRep` would be extremely welcome, thank you. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10193#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10193: TypeRep Show instance doesn't add parens around type operators -------------------------------------+------------------------------------- Reporter: pawel.nowak | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: libraries/base | Version: 7.10.1-rc3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by harpocrates): * status: new => closed * resolution: => fixed Comment: I believe this was (inadvertently) fixed in 3397396a385ef9f493cf1e20894e88d21dfec48d. In any case, it is fixed as of `ghc-8.6.1`, where the output of the code in the ticket description is now `(:*:) Char Char`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10193#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC