Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does ghci desugar type lists and type families? Can this be selectively disabled?
    text
    copied!<p>I'm trying to make the types ghci displays for my libraries as intuitive as possible, but I'm running into a lot of difficulties when using more advanced type features.</p> <p>Let's say I have this code in a file:</p> <pre><code>{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE TypeOperators #-} import GHC.TypeLits data Container (xs::[*]) = Container </code></pre> <p>I load it up in ghci, then I type the following command:</p> <pre><code>ghci&gt; :t undefined :: Container '[String,String,String,String,String] </code></pre> <p>Unfortunately, ghci gives me the rather ugly looking:</p> <pre><code>:: Container ((':) * String ((':) * String ((':) * String ((':) * String ((':) * String ('[] *)))))) </code></pre> <p>ghci has removed the sugar for type level strings. Is there any way to prevent ghci from doing this and giving me just the pretty version?</p> <hr> <p>On a related note, lets say I create a type level <code>Replicate</code> function </p> <pre><code>data Nat1 = Zero | Succ Nat1 type family Replicate (n::Nat1) x :: [*] type instance Replicate Zero x = '[] type instance Replicate (Succ n) x = x ': (Replicate n x) type LotsOfStrings = Replicate (Succ (Succ (Succ (Succ (Succ Zero))))) String </code></pre> <p>Now, when I ask ghci for a type using <code>LotsOfStrings</code>:</p> <pre><code>ghci&gt; :t undefined :: Container LotsOfStrings </code></pre> <p>ghci is nice and gives me the pretty result:</p> <pre><code>undefined :: Container LotsOfStrings </code></pre> <p>But if I ask for the <code>Replicate</code>d version,</p> <pre><code>ghci&gt; :t undefined :: Container (Replicate (Succ (Succ (Succ (Succ (Succ Zero))))) String) </code></pre> <p>ghci substitutes in for the type family when it didn't do that for the type synonym:</p> <pre><code>:: Container ((':) * [Char] ((':) * [Char] ((':) * [Char] ((':) * [Char] ((':) * [Char] ('[] *)))))) </code></pre> <p>Why is ghci doing the substitution for the type family, but not the type synonym? Is there a way to control when ghci will do the substitution?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload