Imms is written primarily in C# and targets that language. But the library has a separate companion assembly, Imms.FSharp, that provides various extensions and modules for use with F#.
The following are the components of the F# Integration library.
Common Aliases
The Imms library provides aliases for many collection-related types found in the .NET Framework, to better match F#‘s concise style. Examples include:
Kvp<'k,'v>forKeyValuePair<'TKey, 'TValue>.IEq<'a>forIEqualityComparer<'T>.ICmp<'a>forIComparer<'T>IIter<'a>forIEnumerator<'T>
Module bindings
The F# companion library offers a module for each of the Imms collections, with module bindings for all the operations exposed by the standard interface. These modules also handle a few other things to make the collections more convenient to work with:
- Conversion to and from F#‘s function and
Optiontypes, as required. - Provide a few extra functions to match the spirit of the F# collection library.
- Impose
: equalityand: comparisonconstraints, as required. - Provide conversion to and from F# collection types.
Active Patterns
The F# companion library comes with a powerful set of active patterns for decomposing Imms sequential collections:
Last(initial, last)allows decomposing collections from the end. Examples areLast1(initial, last),Last2(initial, last1, last2), etc.First(head, tail)allows decomposing collections from the beginning.Mid(head, mid, last)allows decomposing a collection by one element from each side.Nilmatches an empty collection.
Collection Expressions
The F# library also provides computation expressions for building Imms collections. Here are some examples of how they are used:
let lst = immList {
for i in 0 .. 10 do yield i
}
let map = immMap {
for i in 0 .. 10 do yield Kvp(i, i)
}