The F#.NET Journal just published an article about garbage collection: "When performance is important in a garbage collected language such as F# it is useful to have some understanding of the costs of operations that the garbage collector performs. This article provides an introduction to garbage collection, an overview of the processes performed by generational garbage collectors for multithreaded programs and goes on to examine some F# programs that deliberately exhibit pathological behaviour and presents workarounds that alleviate or even eliminate the costs associated with garbage collection on .NET..."
The F#.NET Journal just published an article about purely functional data structures: "Purely functional data structures such as the Set and Map collections provided by the F# standard library have many advantages over traditional imperative collections, particularly clarity due to the absence of mutation, but their performance can be much worse. Benchmarks have shown the F# Set and Map running up to 40× slower than the imperative HashSet and Dictionary collections provided by .NET. This article describes the design and implementation of a hash trie implementation of a set that is up to 7× faster to construct and up to 4.5× faster to search than the F# set..."
type Expr=|Int of int|Var of string|Add of Expr*Expr|Mul of Expr*Expr|Pow of Expr*Exprstatic member (~-) f =Mul(Int-1, f)static member (+)(f, g)=Add(f, g)static member (*)(f, g)=Mul(f, g)static member (/) (f, g) = Mul(f, Pow(g, Int -1))
cosine (Int 0) (Int 1) Int (~-) (+) (*) (/)3(Var"x")
To make it faster, hoist the common subexpression -x*x out of loop.