Module

Prim

The Prim module is embedded in the PureScript compiler in order to provide compiler support for certain types — for example, value literals, or syntax sugar.

#Function

data Function :: Type -> Type -> Type

A function, which takes values of the type specified by the first type parameter, and returns values of the type specified by the second. In the JavaScript backend, this is a standard JavaScript Function.

The type constructor (->) is syntactic sugar for this type constructor. It is recommended to use (->) rather than Function, where possible.

That is, prefer this:

f :: Number -> Number

to either of these:

f :: Function Number Number
f :: (->) Number Number

#Array

data Array :: Type -> Type

An Array: a data structure supporting efficient random access. In the JavaScript backend, values of this type are represented as JavaScript Arrays at runtime.

Construct values using literals:

x = [1,2,3,4,5] :: Array Int

#Record

data Record :: # Type -> Type

The type of records whose fields are known at compile time. In the JavaScript backend, values of this type are represented as JavaScript Objects at runtime.

The type signature here means that the Record type constructor takes a row of concrete types. For example:

type Person = Record (name :: String, age :: Number)

The syntactic sugar with curly braces { } is generally preferred, though:

type Person = { name :: String, age :: Number }

#Number

data Number :: Type

A double precision floating point number (IEEE 754).

Construct values of this type with literals:

y = 35.23 :: Number
z = 1.224e6 :: Number

#Int

data Int :: Type

A 32-bit signed integer. See the purescript-integers package for details of how this is accomplished when compiling to JavaScript.

Construct values of this type with literals:

x = 23 :: Int

#String

data String :: Type

A String. As in JavaScript, String values represent sequences of UTF-16 code units, which are not required to form a valid encoding of Unicode text (for example, lone surrogates are permitted).

Construct values of this type with literals, using double quotes ":

x = "hello, world" :: String

Multi-line string literals are also supported with triple quotes (""").

#Char

data Char :: Type

A single character (UTF-16 code unit). The JavaScript representation is a normal String, which is guaranteed to contain one code unit. This means that astral plane characters (i.e. those with code point values greater than 0xFFFF) cannot be represented as Char values.

Construct values of this type with literals, using single quotes ':

x = 'a' :: Char

#Boolean

data Boolean :: Type

A JavaScript Boolean value.

Construct values of this type with the literals true and false.

#Partial

class Partial 

The Partial type class is used to indicate that a function is partial, that is, it is not defined for all inputs. In practice, attempting to use a partial function with a bad input will usually cause an error to be thrown, although it is not safe to assume that this will happen in all cases. For more information, see the Partial type class guide.

#Fail

class Fail (message :: Symbol) 

The Fail type class is part of the custom type errors feature. To provide a custom type error when someone tries to use a particular instance, write that instance out with a Fail constraint.

For more information, see the Custom Type Errors guide.

#Warn

class Warn (message :: Symbol) 

The Warn type class allows a custom compiler warning to be displayed.

For more information, see the Custom Type Errors guide.

#Union

class Union (l :: # Type) (r :: # Type) (u :: # Type) | l r -> u, r u -> l, u l -> r

The Union type class is used to compute the union of two rows of types (left-biased, including duplicates).

The third type argument represents the union of the first two.

#RowCons

class RowCons (l :: Symbol) (a :: # Type) (i :: Type) (o :: Type) | l a i -> o, l o -> a i

The RowCons type class is a 4-way relation which asserts that one row of types can be obtained from another by inserting a new label/type pair on the left.

#TypeConcat

data TypeConcat :: Symbol -> Symbol -> Symbol

The TypeConcat type constructor concatenates two Symbols in a custom type error.

For more information, see the Custom Type Errors guide.

#TypeString

data TypeString :: Type -> Symbol

The TypeString type constructor renders any concrete type into a Symbol in a custom type error.

For more information, see the Custom Type Errors guide.

#Type

kind Type

Type (also known as *) is the kind of all proper types: those that classify value-level terms. For example the type Boolean has kind Type; denoted by Boolean :: Type.

#Symbol

kind Symbol

Symbol is the kind of type-level strings.

Construct types of this kind using the same literal syntax as documented for strings.