A simplified (non-effectful) definition of Stream from the streaming library reads like this:
data Stream f = Step (f (Stream f))
| Return
I'm trying to understand what the motivation for introducing this functor f is.
A typical such f is Of a, with Of defined as
data Of a b = !a :> b
deriving Functor
When I read f as Of a in the definition of Stream this sort of makes sense, Of a b is something like an a followed by more that is obtainable from b. With this interpretation, the f (Stream f) in the definition of Stream reads something like Of a (Stream (Of a)). But in this case a simpler version would have been
data Stream a = Step a (Stream a)
| Return
I struggle to understand why the generalization with this functor f is used. In the introduction the author says that Stream
... can be used to stream successive distinct steps characterized by any functor
f
and
the general type
Stream f m rexpresses a succession of steps ... with a shape determined by the 'functor' parameterf.
But in Streaming.Prelude the only functors I can find are Or a, Stream (Of a) m and Identity. The first one makes a stream of as, the second a stream of streams, the third achieves 'erasure'.
I really don't get it. I can achieve all of these things, i.e. simple stream of as, stream of streams, and erasure, without using this f in Stream.
What does this functor f do that can't be done otherwise?