Show TYPE 'Lifted/TYPE 'Unlifted as */# in Show TypeRep instance
authorRyanGlScott <ryan.gl.scott@gmail.com>
Sun, 17 Jan 2016 18:28:10 +0000 (19:28 +0100)
committerBen Gamari <ben@smart-cactus.org>
Sun, 17 Jan 2016 22:40:42 +0000 (23:40 +0100)
Kind equalities changed how `*`/`#` are represented internally, which
means that showing a `TypeRep` that contains either of those kinds
produces a rather gross-looking result, e.g.,

```
> typeOf (Proxy :: Proxy 'Just)
Proxy (TYPE 'Lifted -> Maybe (TYPE 'Lifted)) 'Just
```

We can at least special-case the `Show` instance for `TypeRep` so that
it prints `*` to represent `TYPE 'Lifted` and `#` to represent `TYPE
'Unlifted`.

Addresses one of the issues uncovered in #11334.

Test Plan: ./validate

Reviewers: simonpj, hvr, austin, goldfire, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1757

GHC Trac Issues: #11334

libraries/base/Data/Typeable/Internal.hs
libraries/base/tests/T11334.hs [new file with mode: 0644]
libraries/base/tests/T11334.stdout [new file with mode: 0644]
libraries/base/tests/all.T

index 548df30..46e6e82 100644 (file)
@@ -357,7 +357,10 @@ instance Show TypeRep where
   showsPrec p (TypeRep _ tycon kinds tys) =
     case tys of
       [] -> showsPrec p tycon
-      [x]   | tycon == tcList -> showChar '[' . shows x . showChar ']'
+      [x@(TypeRep _ argCon _ _)]
+        | tycon == tcList -> showChar '[' . shows x . showChar ']'
+        | tycon == tcTYPE && argCon == tc'Lifted   -> showChar '*'
+        | tycon == tcTYPE && argCon == tc'Unlifted -> showChar '#'
       [a,r] | tycon == tcFun  -> showParen (p > 8) $
                                  showsPrec 9 a .
                                  showString " -> " .
diff --git a/libraries/base/tests/T11334.hs b/libraries/base/tests/T11334.hs
new file mode 100644 (file)
index 0000000..22864d9
--- /dev/null
@@ -0,0 +1,11 @@
+{-# LANGUAGE DataKinds #-}
+module Main (main) where
+
+import Data.Typeable
+import GHC.Types
+
+main :: IO ()
+main = do
+  print (typeOf (Proxy :: Proxy 'Just))
+  print (typeOf (Proxy :: Proxy (TYPE 'Lifted)))
+  print (typeOf (Proxy :: Proxy (TYPE 'Unlifted)))
diff --git a/libraries/base/tests/T11334.stdout b/libraries/base/tests/T11334.stdout
new file mode 100644 (file)
index 0000000..a00f275
--- /dev/null
@@ -0,0 +1,3 @@
+Proxy (* -> Maybe *) 'Just
+Proxy * *
+Proxy * #
index 0cb48bb..06ef3bb 100644 (file)
@@ -210,4 +210,5 @@ test('T9848',
         , only_ways(['normal'])],
       compile_and_run,
       ['-O'])
-test('T10149',normal, compile_and_run,[''])
+test('T10149', normal, compile_and_run, [''])
+test('T11334', normal, compile_and_run, [''])