Skip to main content
Version: Next

Native Types

This page describes the built-in data shapes that are part of the language itself rather than stdlib modules.

Tasks​

Type form: 'a task

FormSignatureDescription
Task.spawn (fun () -> expr)(unit -> 'a) -> 'a taskStarts concurrent work and returns a task handle.
Task.await taskValue'a task -> 'aWaits for completion and returns the task result.
let pending = Task.spawn (fun () -> 40 + 2)
let answer = Task.await pending

Tasks are opaque values. They do not expose indexers or fields. The 'a task type is native to the language. An embedding host can choose whether to expose Task.spawn and Task.await.

Lists​

Type form: 'a list

FormSignatureDescription
[first..last]int listInclusive integer range; steps by +1 or -1 toward the final bound.
[]'a listEmpty list literal.
head :: tail'a -> 'a list -> 'a listPrepends one item to a list.
left @ right'a list -> 'a list -> 'a listConcatenates two lists.
values[index]'a list -> int -> 'a optionZero-based optional indexer. Negative or out-of-range indices return None.
let xs = [10; 20; 30]
let maybeSecond = xs[1]

Maps​

Type forms: 'v map for string keys, or 'v map['key] for explicit key types.

Map keys may be string, int, bool, or a union whose cases all have no payload. Use value map[key] for explicit key annotations; value map remains the string-keyed shorthand.

FormSignatureDescription
{}'v map['key]Empty map literal.
{ [key] = value }'key -> 'v -> 'v map['key]Map literal entry syntax.
values[key]'v map['key] -> 'key -> 'v optionOptional key lookup. Missing keys return None.
{ ..tail }'v map['key] -> 'v map['key]Spread syntax used when building or updating a map.
let scores = { ["math"] = 18; ["english"] = 16 }
let maybeMath = scores["math"]

Options​

Type form: 'a option

FormSignatureDescription
Some value'a -> 'a optionWraps a present value.
None'a optionRepresents the absence of a value.

Use pattern matching or Option.* helpers to consume options.

Tuples​

Type form: (t1 * t2 * ...)

FormSignatureDescription
(a, b)'a * 'bTuple literal.
let (a, b) = valuebinding syntaxIntroduces two bindings from a tuple; this is not a function returning unit.
tuple pattern matching('a * 'b) -> 'rUse match value with (a, b) -> ... to decompose tuples.

Tuples do not have a native indexer. Destructure them instead.

Records​

Type form: { Field: t; ... }

FormSignatureDescription
{ Name = value }field-set dependentRecord literal requiring an unambiguous declared record field set.
record.Field{ Field: 'a; ... } -> 'aField access by name.
{ record with Field = value }same record type -> same record typeCopy a record and replace existing fields.
{| Field = value |}structural recordStructural record literal.
{| record with Field = value |}record-shape dependentStructural record update; may add fields; existing field types must remain compatible.

Host-managed types​

A .NET host can register named types with immutable visible fields and an opaque payload. Scripts can read and match visible fields and transport complete values, including as collection values. They cannot construct these types from record literals or use either record-update syntax on them. Equality, formatting, and JSON serialization use visible fields only; JSON decoding cannot restore host-managed state.

These are host-supplied types rather than built-in record declarations. Hosts can also register script-constructible records; those use ordinary record construction and update rules. See Host-Provided Types for registration and invocation examples.

Unions​

Type form: type Shape = | Point | Circle of int

FormSignatureDescription
Casecase dependentUnion constructor without payload.
Case valuepayload type -> union typeUnion constructor with payload.
union pattern matchingunion type -> 'rUse match value with Case x -> ... to branch on union cases.

Scalars​

Primitive built-in types:

  • int: signed 64-bit integer
  • float: double-precision floating-point number
  • bool
  • string
  • unit

These do not use indexers. For parsing and formatting helpers, see Int, Float, Bool Modules and String Module.

Numeric meta-type​

numeric constrains inference to int or float. It is available in function annotations and inferred editor signatures, with no additional runtime value shape.

OperationOperand typesResult
+, -, *, /Two int values or two float valuesSame concrete type as the operands
<, >, <=, >=Two int values or two float valuesbool
%Two int valuesint

Mixed numeric types and nonnumeric operands are rejected. + does not concatenate strings, lists, or maps. Use String.concat for strings and @ for lists.

See Type System for the type hierarchy and specialization examples.

Function values​

A function type has the form argument -> result. Arrows associate to the right, so int -> string -> bool describes a function that takes an int and returns a function of type string -> bool.

Apply a function with whitespace, as in format value. For a function with a unit parameter, pass (), as in ping (). You can also pass functions as arguments, return them from other functions, or capture them in closures. See Syntax and Operators for application precedence.

Type tokens​

typeof Name produces a runtime value of type type that identifies a declared FScript type. Scripts can pass these tokens to host functions that accept them.