title: How to define constant heterogeneous streams in Haskell?
body: <p>I understand how to define both homogeneous and heterogeneous streams in Haskell.</p>
  <pre><code>-- Type-invariant streams.
  data InvStream a where
     (:::) :: a -&gt; InvStream a -&gt; InvStream a
  
  -- Heterogeneous Streams.
  data HStream :: InvStream * -&gt; * where
     HCons :: x -&gt; HStream xs -&gt; HStream (x '::: xs)
  </code></pre>
  <p>How can we define a constant stream as a particular case of a heterogeneous stream? If I try to define a type family of streams of constant type, I get a &quot;Reduction stack overflow&quot; error. I imagine this has to do with the type checking algorithm not being lazy enough and trying to compute the whole <code>Constant a</code> stream of types.</p>
  <pre><code>type family Constant (a :: *) :: InvStream * where
    Constant a = a '::: Constant a
  
  constantStream :: a -&gt; HStream (Constant a)
  constantStream x =  HCons x (constantStream x)
  </code></pre>
  <p>Is there any way I can get around this problem and define constant heterogeneous streams? Is there any other similar construction I should be trying instead?</p>