Q:

Is there a name for this pattern "type 'a foldedSequence = Empty | Value of 'a * (unit->'a foldedSequence )"

I have been working with some f# parsers and some streaming software and I find myself using this pattern more and more. I find it to be a natural alternative to sequences and it has some natural advantages.
here are some example functions using the type.
type foldedSequence<'a> = 
    | Empty
    | Value of ' a * (unit -> 'a foldedSequence)

let rec createFoldedSequence fn state = 
    match fn state with
    | None -> Empty
    | Some(value, nextState) ->
        Value(value, (fun () -> unfold fn nextState))

let rec filter predicate = 
    function 
    | Empty -> Empty
    | Value(value, nextValue) -> 
        let next() = filter predicate(nextValue())
        if predicate value then Value(value, next)
        else next()

let toSeq<'t> = 
    Seq.unfold<'t foldedSequence, 't>(function 
        | Empty -> None
        | Value(value, nextValue) -> Some(value, nextValue()))

It has been very helpful I would like to know if it has a name so I can research some tips and tricks for it

A:

To add to the existing answers, I think Haskellers might call a generalised version of this this a list monad transformer. The idea is that your type definition looks almost like ordinary F# list except that there is some additional aspect to it. You can imagine writing this as:
type ListTransformer<'T> = 
   | Empty
   | Value of 'T * M<ListTransformer<'T>>

By supplying specific M, you can define a number of things:

M<'T> = 'T gives you the ordinary F# list type
M<'T> = unit -> 'T gives you your sequence that can be evaluated lazily
M<'T> = Lazy<'T> gives you LazyList (which caches already evaluated elements)
M<'T> = Async<'T> gives you asynchronous sequences

It is also worth noting that in this definition LazyTransformer<'T> is not itself a delayed/lazy/async value. This can cause problems in some cases - e.g. when you need to perform some async operation to decide whether the stream is empty - and so a better definition is:
type ListTransformer<'T> = M<ListTransformerInner<'T>>
and ListTransformerInner<'T> =
   | Empty
   | Value of 'T * ListTransformer<'T>

