I have this code where these functions have been made:
- creates an infinite list out of the given stream;
- creates a stream for the given iteration function and the starting stream element (seed);
- merges two streams into one so that their elements are interleaved.
The code is as follows:
data Stream a = Cons a (Stream a)
streamToList :: Stream a -> [a]
streamToList (Cons x xs) = x : streamToList xs
streamIterate :: (a -> a) -> a -> Stream a
streamIterate f x = Cons x (streamIterate f (f x))
streamIterLeave :: Stream a -> Stream a -> Stream a
streamIterLeave (Cons x xs) ys = Cons x (streamIterLeave ys xs)
Now what I am having problems with is I have no idea how to check this code on ghci. To be more specific, how do I input a stream into the command line?
For example I tried streamToList [1,2,3] ; streamToList (1,2,3); streamToList 1,2,3 and none of them seem to be working.
Help is very much appreciated!