Types
Typescript Types
Term
is a Typescript type defined inplu-ts
.- Every value in
plu-ts
is aTerm
. In Typescript, we say each value extends Term (in the same way that "Dog" extends "Mammal"). - A
Term
also keeps track of the type of the value it holds.
The possible types a Term
can keep track of are defined in PTypes, and listed here:
PUnit
a unique value that has no real meaning; you can see it asplu-ts
version ofundefined
ornull
in TypescriptPInt
a signed integer that can be as big as you wantPBool
a boolean valuePByteString
equivalent of aBuffer
or aUint8Array
PString
equivalent of the Typescriptstring
PData
equivalent of theobject
type in Typescript (it is the low level representation ofPStruct
s that we'll cover in a moment, so you usually won't usePData
)PList<PType>
equivalent of an Array in Typescript; note that all the elements in the list must be of the samePType
PPair<PType1, PType2>
equivalent of a Typescript tuple ([ type1 , type2 ]
)PDelayed<PType>
a delayed computation that returns a value of typePType
; the computation can be run by passing the delayed value to thepforce
functionPLam<PInput, POutput>
a function that takes one single argument of typePInput
and returns something of typePOutput
PFn<[ PInput_0 , ...PType[] ],POutput>
a function that takes multiple arguments (at least one) and returns something of typePOutput
PAlias<PType>
just an alias of the provided type; it behaves exactly like the Types of its argument, soPAlias<PInt>
is equivalent to aPInt
. This is useful for keeping track of a different meaning the type might have.PStruct<{...}>
an abstraction overPData
, useful to construct more complex data structures.
plu-ts
Types
plu-ts
would not be a strongly typed language if limited to Typescript types, because the types of Typescript are only useful during compilation to javascript; and then everything is untyped!
Important Note:
Typescript can be compiled to Javascript. When this happens, the resulting Javascript is untyped!
Therefore:
For this reason plu-ts
implements its own type through some constants and functions can be imported.
In the same order of above, the plu-ts
equivalents are:
PUnit
->unit
PInt
->int
PBool
->bool
PByteString
->bs
PString
->str
PData
->data
PList
->list( type )
PPair
->pair( type1, type2 )
PDelayed
->delayed( type )
PLam
->lam( from, to )
PFn
->fn([ ...inputs ], output )
- aliases types and structs types will be retreived by the
type
static property of the classes (explained in the dedicated section for aliases and structs)