FSharp.Core is the library every F# program uses. Its namespaces are FSharp.Core (the basic types and Operators), FSharp.Collections (List, Array, Seq, Map, Set), FSharp.Control (Async, MailboxProcessor, Event, Observable, tasks), FSharp.Quotations, FSharp.Reflection, FSharp.NativeInterop and FSharp.Linq. The names on this page are taken from the library’s interface files; the ones the viewer colours specially are marked. Most are opened automatically.
Types
Built-in type names the viewer colours as types: int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 byte sbyte char string bool float float32 double single decimal unit obj objnull exn nativeint unativeint bigint array list option voption nativeptr voidptr byref inref outref. They are abbreviations (type int = int32, type float = Double, type string = String, type obj = Object, type exn = Exception, type byte = Byte and so on) except the generic ones, which are defined in the library: Option<'T>, ValueOption<'T>, List<'T>, Result<'T,'TError>, Choice<…> (two to seven cases), Lazy<'T>, Ref<'T>, ResizeArray<'T>, FSharpFunc<'T,'U>, Handler<'T>, IEvent<…>, IDelegateEvent<…>, Map<'K,'V>, Set<'T>, Async<'T>, Expr and Expr<'T>. Other names written with a capital letter (List, String, Console) are coloured as types or modules by their capital.
The attributes of the library (all end in Attribute, and are written without it): AbstractClass AllowNullLiteral AutoOpen CLIEvent CLIMutable Class CompiledName CompilerMessage CustomComparison CustomEquality CustomOperation DefaultAugmentation DefaultValue EntryPoint Experimental GeneralizableValue InlineIfLambda Interface Literal Measure NoComparison NoCompilerInlining NoDynamicInvocation NoEquality OptionalArgument ProjectionParameter ReferenceEquality ReflectedDefinition RequireQualifiedAccess RequiresExplicitTypeArguments Sealed Struct StructuralComparison StructuralEquality StructuredFormatDisplay TailCall Unverifiable VolatileField. In an attribute list the viewer colours any name as a type.
Operators and top-level functions
The module Operators and the module of top-level operators are opened by default. The viewer colours these names as library functions:
| Group | Names |
|---|---|
| errors | raise rethrow reraise failwith failwithf invalidArg invalidOp nullArg exit |
| values | fst snd id ignore not ref incr decr box unbox tryUnbox isNull defaultArg defaultValueArg hash limitedHash compare max min lock using enum |
| types and names | typeof typedefof nameof sizeof |
| maths | abs acos asin atan atan2 ceil exp floor sign round log log10 sqrt cos cosh sin sinh tan tanh truncate pown |
| output | printf printfn eprintf eprintfn sprintf fprintf fprintfn |
| collections and builders | dict readOnlyDict set array2D seq async task backgroundTask query |
| constants (literals) | nan nanf infinity infinityf stdin stdout stderr and the cases None Some Ok Error |
The conversion functions int, uint, int8, uint8, int16, uint16, int32, uint32, int64, uint64, byte, sbyte, float, float32, double, single, decimal, char, string, nativeint, unativeint have the same names as the types. The operators in the library, by their symbols, are those of the lexical page and the documentation’s operator tables: + - * / % **, = <> < > <= >=, && ||, &&& ||| ^^^ ~~~ <<< >>>, |> ||> |||> <| <|| <||| >> <<, := ! @ ^ :: and the range operator ... Other names in the interface include defaultIfNull, nullV, nonNull, withNull (nullness, F# 9), methodhandleof and the active patterns (|Failure|_|), (|KeyValue|), (|Null|NonNull|).
Printf
The module Printf holds printf printfn eprintf eprintfn sprintf fprintf fprintfn bprintf kprintf ksprintf kfprintf kbprintf failwithf. A format string is checked against the arguments at compile time. Format specifiers are %b (bool), %s (string), %c (char), %d and %i (signed integers), %u (unsigned), %x %X %o (hex, octal), %B (binary), %e %E %f %F %g %G %M (floating point and decimal), %O (ToString), %A (any value, pretty printed), %a and %t (custom printers) and %% for a percent sign. A placeholder is %[flags][width][.precision][type]; the flags are 0 (pad with zeros), - (left-justify), + and a space (show a sign for positive numbers); a width of * takes the width from an argument; the # flag is a compile-time error. Values are formatted with the invariant culture. (This table is from the documentation’s plain text formatting page.)
The collection modules
After a module name and a dot, the viewer colours the next name as a function. These are the function names in the interface files, per module.
| Module | Functions |
|---|---|
List | allPairs append average averageBy choose chunkBySize collect compareWith concat contains countBy distinct distinctBy empty exactlyOne except exists exists2 filter find findBack findIndex findIndexBack fold fold2 foldBack foldBack2 forall forall2 groupBy head indexed init insertAt insertManyAt isEmpty item iter iter2 iteri iteri2 last length map map2 map3 mapFold mapFoldBack mapi mapi2 max maxBy min minBy nth ofArray ofSeq pairwise partition permute pick randomChoice randomChoiceBy randomChoiceWith randomChoices randomChoicesBy randomChoicesWith randomSample randomSampleBy randomSampleWith randomShuffle randomShuffleBy randomShuffleWith reduce reduceBack removeAt removeManyAt replicate rev scan scanBack singleton skip skipWhile sort sortBy sortByDescending sortDescending sortWith splitAt splitInto sum sumBy tail take takeWhile toArray toSeq transpose truncate tryExactlyOne tryFind tryFindBack tryFindIndex tryFindIndexBack tryHead tryItem tryLast tryPick unfold unzip unzip3 updateAt where windowed zip zip3 |
Seq | allPairs append average averageBy cache cast choose chunkBySize collect compareWith concat contains countBy delay distinct distinctBy empty exactlyOne except exists exists2 filter find findBack findIndex findIndexBack fold fold2 foldBack foldBack2 forall forall2 groupBy head indexed init initInfinite insertAt insertManyAt isEmpty item iter iter2 iteri iteri2 last length map map2 map3 mapFold mapFoldBack mapi mapi2 max maxBy min minBy nth ofArray ofList pairwise permute pick randomChoice randomChoiceBy randomChoiceWith randomChoices randomChoicesBy randomChoicesWith randomSample randomSampleBy randomSampleWith randomShuffle randomShuffleBy randomShuffleWith readonly reduce reduceBack removeAt removeManyAt replicate rev scan scanBack singleton skip skipWhile sort sortBy sortByDescending sortDescending sortWith splitInto sum sumBy tail take takeWhile toArray toList transpose truncate tryExactlyOne tryFind tryFindBack tryFindIndex tryFindIndexBack tryHead tryItem tryLast tryPick unfold updateAt where windowed zip zip3 |
Array | allPairs append average averageBy blit choose chunkBySize collect compareWith concat contains copy countBy create distinct distinctBy empty exactlyOne except exists exists2 fill filter find findBack findIndex findIndexBack fold fold2 foldBack foldBack2 forall forall2 get groupBy head indexed init insertAt insertManyAt isEmpty item iter iter2 iteri iteri2 last length map map2 map3 mapFold mapFoldBack mapi mapi2 max maxBy min minBy ofList ofSeq pairwise partition partitionWith permute pick randomChoice randomChoiceBy randomChoiceWith randomChoices randomChoicesBy randomChoicesWith randomSample randomSampleBy randomSampleWith randomShuffle randomShuffleBy randomShuffleInPlace randomShuffleInPlaceBy randomShuffleInPlaceWith randomShuffleWith reduce reduceBack removeAt removeManyAt replicate rev scan scanBack set singleton skip skipWhile sort sortBy sortByDescending sortDescending sortInPlace sortInPlaceBy sortInPlaceWith sortWith splitAt splitInto sub sum sumBy tail take takeWhile toList toSeq transpose truncate tryExactlyOne tryFind tryFindBack tryFindIndex tryFindIndexBack tryHead tryItem tryLast tryPick unfold unzip unzip3 updateAt where windowed zeroCreate zip zip3; the modules Array2D, Array3D and Array4D hold the functions for grids (their names are not listed here) |
Option | bind contains count defaultValue defaultWith exists filter flatten fold foldBack forall get isNone isSome iter map map2 map3 ofNullable ofObj orElse orElseWith toArray toList toNullable toObj; ValueOption (in the same interface file) has the matching functions with ofOption, toOption, ofValueOption and toValueOption conversions |
String | collect concat exists filter forall init iter iteri length map mapi replicate |
Map | add change containsKey count empty exists filter find findKey fold foldBack forall isEmpty iter keys map maxKeyValue minKeyValue ofArray ofList ofSeq partition pick remove toArray toList toSeq tryFind tryFindKey tryPick values |
Set | add contains count difference empty exists filter fold foldBack forall intersect intersectMany isEmpty isProperSubset isProperSuperset isSubset isSuperset iter map maxElement minElement ofArray ofList ofSeq partition remove singleton toArray toList toSeq union unionMany |
Result | bind contains count defaultValue defaultWith exists fold foldBack forall isError isOk iter map mapError toArray toList toOption toValueOption |
Async (static members) | AsBeginEnd AwaitEvent AwaitIAsyncResult AwaitTask AwaitWaitHandle CancelDefaultToken CancellationToken Catch Choice DefaultCancellationToken FromBeginEnd FromContinuations Ignore OnCancel Parallel RunSynchronously Sequential Sleep Start StartAsTask StartChild StartChildAsTask StartImmediate StartImmediateAsTask StartWithContinuations SwitchToContext SwitchToNewThread SwitchToThreadPool TryCancelled |
Other modules and classes
Checked(checked arithmetic operators) andUnchecked(defaultof,hash,compare,equals),LanguagePrimitives(GenericZero,GenericOne,FloatWithMeasureand similar, equality and comparison helpers),NativePtr,EventandObservable(combinators for events andIObservable),OptimizedClosures,NumericLiterals(NumericLiteralI, the module behind1I).MailboxProcessor<'Msg>(an agent with a message queue;Start,Post,PostAndReplyandReceive),Lazy<'T>,Event<'T>,Quotations.Exprand its pattern modules (see quotations),FSharp.Reflection(FSharpTypeandFSharpValuefor records, unions and tuples),FSharp.Linq(thequerybuilder and the nullable operators).- Task support:
taskandbackgroundTaskbuilders, theTaskandValueTaskhelper modules of the F# 11 library,Async.AwaitTaskandAsync.StartAsTask.
Not described
Known, not yet covered
- Reference: the signature, the meaning and an example of each function are not given; only names are listed. The documentation text of each function (the API reference at fsharp.github.io/fsharp-core-docs) was not read. Missing from the lists: the internal and primitive modules (
IntrinsicFunctions,HashCompare,OperatorIntrinsics),MailboxProcessormembers in full,EventandObservablefunction names, theArray2D,Array3DandArray4Dfunctions in full,FSharp.Reflectionmembers,LanguagePrimitivesmembers,Asyncinstance helpers and the extension members ofCommonExtensions(AsyncRead,AsyncWriteand others). - Reference: each row of the module table was made by listing the
valnames of the module’s interface file and removing the internal helpers, so a name that is declared another way (a member of a type, or in a nested module) is missing, and theOptionrow mixes in what the interface file keeps forValueOption. The F# 11 modules for tasks and async helpers are named from the release page, not from the interface files. - Reference: the structured formatting rules behind
%A(layout settings,StructuredFormatDisplay, customising withAddPrinter) are not described.
Unknown
- Reference: the interface files read are those of the
mainbranch at the download; the FSharp.Core version that ships with a given SDK may have fewer functions (the random functions came with F# 9,insertAtand the others with F# 6).
See also
- Types – how the collection types are written
- Computation expressions –
seq,async,taskandquery