I have a structure to define lazily evaluated sequences which are defined as
datatype 'a seq = Cons of 'a option * (unit -> 'a seq)
and I have a function map() that maps a function of type ('a->'b) to the values in the sequence.
val map : ('a -> 'b) -> 'a seq -> 'b seq
However when I define the function, it doesn't match the type provided by the signature, and I cannot for the life of me figure out how to make it match. Everything I tried either didn't affect it or made it even worse.
fun map fu (Cons(NONE, f)) = map fu (f())
| map fu (Cons(SOME x, f)) = Cons(fu(x), fn () => map(fu) (f()))
Which gives me the error type in structure doesn't match signature
spec: ('a -> 'b) -> 'a ?.Seq.seq -> 'b ?.Seq.seq
actual: ('a -> 'b option) -> 'a ?.Seq.seq -> 'b ?.Seq.seq