If i have a function f and a stream s . How can I apply this function to the stream. Similiar to how a List.map would work.
It is an infinite stream of any type:
type 'a stream = Cons of 'a * (unit -> 'a stream)
I have come up with this, which is surely wrong but at least it reperesents what i am trying to do
type 'a stream = Cons of 'a * (unit -> 'a stream)
let rec map f (cons(x,xsf)) = f x then map f (xsf)
Something like this ought to work:
This defines a
Streammodule where we can keep helpful functions for dealing with streams (analogous to theListmodule), with just a singlemapfunction in it. The map function takes a functionfand a stream made by consingxto the functionxs, and maps f over the stream, returning a new stream whose head isf xand whose tail is gotten by mappingfover the stream that results from callingxs.