Skip to content

Pretty printing of kind-involving inferred types

An example of inferred types (foo, bar, both), for brevity's sake omitting value-level details:

{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeOperators #-}
import GHC.TypeLits 

data (:::) (sy :: Symbol) ty 
data Key (sy :: Symbol) 
data Rec (rs :: [*])

(*=) :: Key sy -> ty -> Rec '[sy ::: ty]
(*=) = undefined

(.*.) :: (Union xs ys ~ rs) => Rec xs -> Rec ys -> Rec rs
(.*.) = undefined

type family Union (xs :: [*]) (ys :: [*]) :: [*]  where
    Union ((sy ::: t) ': xs) ys = (sy ::: t) ': Union xs ys
    Union '[] ys = ys


fFoo :: Key "foo"
fFoo = undefined

fBar :: Key "bar"
fBar = undefined


foo ::  Rec ((':) * ("foo" ::: [Char]) ('[] *))
foo = fFoo *= "foo"

bar ::  Rec ((':) * ("bar" ::: [Char]) ('[] *))
bar = fBar *= "bar"

both :: Rec ((':) * ("foo" ::: [Char]) ((':) * ("bar" ::: [Char]) ('[] *)))
both = foo .*. bar

There's actually two issues, here: First, the most serious one, GHC prints kind annotations (*) that it can't even parse back, and then [*] types are pretty printed with ': constructors instead of nicely with [,] syntax.

Trac metadata
Trac field Value
Version 7.7
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information