2 people like it.

Factorial with bigint and reduce

Factorial with bigint and reduce

1: 
2: 
3: 
4: 
let factorial n = [1..n] |> List.map (fun e -> bigint e) |> List.reduce (*)

//F# 4.0
//let factorial n = [1..n] |> List.map bigint |> List.reduce (*)
val factorial : n:int -> System.Numerics.BigInteger

Full name: Script.factorial
val n : int
Multiple items
module List

from Microsoft.FSharp.Collections

--------------------
type List<'T> =
  | ( [] )
  | ( :: ) of Head: 'T * Tail: 'T list
  interface IEnumerable
  interface IEnumerable<'T>
  member Head : 'T
  member IsEmpty : bool
  member Item : index:int -> 'T with get
  member Length : int
  member Tail : 'T list
  static member Cons : head:'T * tail:'T list -> 'T list
  static member Empty : 'T list

Full name: Microsoft.FSharp.Collections.List<_>
val map : mapping:('T -> 'U) -> list:'T list -> 'U list

Full name: Microsoft.FSharp.Collections.List.map
val e : int
type bigint = System.Numerics.BigInteger

Full name: Microsoft.FSharp.Core.bigint
val reduce : reduction:('T -> 'T -> 'T) -> list:'T list -> 'T

Full name: Microsoft.FSharp.Collections.List.reduce

More information

Link:http://fssnip.net/rK
Posted:9 years ago
Author:Andriy Tolstoy
Tags: factorial , bigint , reduce