haskell - Why does ghci desugar type lists and type families? Can this be selectively disabled? -
i'm trying make types ghci displays libraries intuitive possible, i'm running lot of difficulties when using more advanced type features.
let's have code in file:
{-# language typefamilies #-} {-# language datakinds #-} {-# language typeoperators #-} import ghc.typelits data container (xs::[*]) = container
i load in ghci, type following command:
ghci> :t undefined :: container '[string,string,string,string,string]
unfortunately, ghci gives me rather ugly looking:
:: container ((':) * string ((':) * string ((':) * string ((':) * string ((':) * string ('[] *))))))
ghci has removed sugar type level strings. there way prevent ghci doing , giving me pretty version?
on related note, lets create type level replicate
function
data nat1 = 0 | succ nat1 type family replicate (n::nat1) x :: [*] type instance replicate 0 x = '[] type instance replicate (succ n) x = x ': (replicate n x) type lotsofstrings = replicate (succ (succ (succ (succ (succ zero))))) string
now, when ask ghci type using lotsofstrings
:
ghci> :t undefined :: container lotsofstrings
ghci nice , gives me pretty result:
undefined :: container lotsofstrings
but if ask replicate
d version,
ghci> :t undefined :: container (replicate (succ (succ (succ (succ (succ zero))))) string)
ghci substitutes in type family when didn't type synonym:
:: container ((':) * [char] ((':) * [char] ((':) * [char] ((':) * [char] ((':) * [char] ('[] *))))))
why ghci doing substitution type family, not type synonym? there way control when ghci substitution?
the workaround know of using :kind. instance,
ghci> :kind (container '[string,string,string,string,string])
gives:
( container '[string,string,string,string,string]) :: *
while
ghci> :kind! (container '[string,string,string,string,string])
will print this:
container
((':)
* [char] ((':) * [char] ((':) * [char] ((':) * [char] ((':) * [char] ('[] *))))))
officially, of course, you're asking ghci different question kind
, works. using undefined ::
sort of workaround anyhow, thought might suffice.
Comments
Post a Comment