Types
Typescript Types
Termis a Typescript type defined inplu-ts.- Every value in
plu-tsis aTerm. In Typescript, we say each value extends Term (in the same way that "Dog" extends "Mammal"). - A
Termalso 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:
PUnita unique value that has no real meaning; you can see it asplu-tsversion ofundefinedornullin TypescriptPInta signed integer that can be as big as you wantPBoola boolean valuePByteStringequivalent of aBufferor aUint8ArrayPStringequivalent of the TypescriptstringPDataequivalent of theobjecttype in Typescript (it is the low level representation ofPStructs 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 samePTypePPair<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 thepforcefunctionPLam<PInput, POutput>a function that takes one single argument of typePInputand returns something of typePOutputPFn<[ PInput_0 , ...PType[] ],POutput>a function that takes multiple arguments (at least one) and returns something of typePOutputPAlias<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->unitPInt->intPBool->boolPByteString->bsPString->strPData->dataPList->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
typestatic property of the classes (explained in the dedicated section for aliases and structs)