Hello everyone,
I came across a type example from a book that I found to be quite complex.
data Stream f m r = Step (f (Stream f m r))
| Effect (m (Stream f m r))
| Return r
data Of a b = a :> b
deriving Show
empty :: Stream f m ()
empty = Return ()
*Main> a = 1 :> empty
*Main> :t a
a :: Num a => Of a (Stream f m ()) -- Got it. Understood
*Main> b = Step a
*Main> :t b
b :: Num a => Stream (Of a) m () -- Seems cryptic.
*Main>
The type constructor Step
belongs to the Stream
data type, so I expected the resulting type to be Stream A B C
. The format of the type, which is Stream (Of a) m ()
, seems to be correct. However, I am having difficulty understanding why the Of a
is added to A
, m
is added to B
, and ()
is added to C
by the compiler. Can someone please help me understand how this works? Thank you.