I understand how to define both homogeneous and heterogeneous streams in Haskell.
-- Type-invariant streams.
data InvStream a where
(:::) :: a -> InvStream a -> InvStream a
-- Heterogeneous Streams.
data HStream :: InvStream * -> * where
HCons :: x -> HStream xs -> HStream (x '::: xs)
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 "Reduction stack overflow" error. I imagine this has to do with the type checking algorithm not being lazy enough and trying to compute the whole Constant a
stream of types.
type family Constant (a :: *) :: InvStream * where
Constant a = a '::: Constant a
constantStream :: a -> HStream (Constant a)
constantStream x = HCons x (constantStream x)
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?