14 people like it.

Fibonacci sequence

Cached fib sequence

1: 
2: 
3: 
4: 
5: 
let fibs =  
    let rec f a b = seq { yield a
                          yield! f b (a+b) }
    f 1 1
    |> Seq.cache
val fibs : seq<int>

Full name: Script.fibs
val f : (int -> int -> seq<int>)
val a : int
val b : int
Multiple items
val seq : sequence:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Core.Operators.seq

--------------------
type seq<'T> = System.Collections.Generic.IEnumerable<'T>

Full name: Microsoft.FSharp.Collections.seq<_>
module Seq

from Microsoft.FSharp.Collections
val cache : source:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.cache
Raw view New version

More information

Link:http://fssnip.net/1u
Posted:6 years ago
Author:Dmitri Pavlenkov
Tags: seq , fibonacci , sequence , cache