Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Seq<'a> = Getter of (unit -> ('a * Seq<'a>) option)
- let PrintSeq (seq: Seq<'a>) =
- let rec _step getter =
- match getter() with
- | None -> ()
- | Some(el, Getter(nextGetter)) ->
- printf "%A, " el
- _step nextGetter
- match seq with
- | Getter(f) -> _step f
- let Map seq f =
- let rec _step getter () =
- match getter() with
- | None -> None
- | Some(el, Getter(nextGetter)) ->
- Some(f el, Getter(_step nextGetter))
- match seq with
- | Getter(g) -> Getter(_step g)
- let Reduce seq f =
- let rec _step value getter =
- match getter() with
- | None -> value
- | Some(el, Getter(nextGetter)) ->
- _step (f value el) nextGetter
- match seq with
- | Getter(g) ->
- match g() with
- | None -> None
- | Some(el, Getter(getter)) -> Some(_step el getter)
- // Sequences
- let Range a b c : Seq<int> =
- let rec _getter x () =
- if x >= b then None
- else Some(x, Getter(_getter (x + c)))
- Getter(_getter a)
- let rng = Range 1 5 1
- let x = Reduce rng (+)
- match x with
- | Some(y) -> printfn "%d" y
- | None -> printfn "neon"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement