203 people like it.

Haskell function : iterate

Implements iterate function from Haskell's Prelude. The function generates an infinite sequence by applying a function to the initial value (first) and then to the result of previous application.

1: 
2: 
3: 
4: 
5: 
6: 
let rec iterate f value = seq { 
  yield value
  yield! iterate f (f value) }

// Returns: seq [1; 2; 4; 8; ...]
Seq.take 10 (iterate ((*)2) 1)
val iterate : f:('a -> 'a) -> value:'a -> seq<'a>

Full name: Script.iterate
val f : ('a -> 'a)
val value : 'a
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 take : count:int -> source:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.take

More information

Link:http://fssnip.net/18
Posted:13 years ago
Author:Nick Palladinos
Tags: haskell functions , seq