Italicized concepts are not yet implemented in any fashion. This is because during primary development of this library, this document functions as both a record and spec.
In addition to these documented in wikipedia, additional monads provided are:
- Future (effectful)
- Arr (Array)
- List (Linked List)
As all monads are applicatives, and all applicatives are functors, the following methods should be guaranteed on each instance:
- map (functor map)
- ap (applicative apply)
- mbind (monadic bind)
On the type constructors are provided
- from (constructor method)
On the types proper are provided
- destructure (provides basic type pattern matched dispatch)
- from (return function)
- lift (lifts a function into a monadically aware function)
- Option Transformer
- Exception Transformer
- Reader Transformer
- State Transformer
- Writer Transformer
- Continuation Transformer
Algebraic Data Type
In the algebraic module, there is a function
data that has the signature
In the concreteSpec is provided names for the type constructors and the number of contained data fields.
type = adtdata"Maybe" Just: 1 None: 0;
Declares a type called
Maybe with two constructors,
None, which wrap 1 and 0
peices of data respectively.
Using this type declaration we can now begin to implement methods against it, using the
This call will create a new type from the old one, so it is important to note that if for some reason you are changing your type at runtime, old instances made before a type created after a call to any of the type adjustment methods will not have any of the new methods.
The signature for the implementation methods is
function(unwrappedData1..unwrappedDataN, methodArgs1...methodArgsN, typeContext).
Which is to say that any and all wrapped data in the type is exposed first, followed by any data that is called on the method,
followed finally by a type context so that access to the type and subtypes related to the implementing type are available.
For any methods that may make sense to have, but not make sense on a instance, a "static" method provider exists.
the best facility for type based dispatch unless you are using objects, we can't easily use and extend a polymorphic
lift function, as we need to know what type we are lifting into. Placing this on the t.Maybe object then makes
the most sense.
Destructuring is a common form of pattern matching with algebraic data types in Haskell. While full destructuring is not supported by ES5, a limited form of destructuring based on type is supported by the algebraic data type provider.
var isJust = typeMaybeinst = typeJust;=== true;
Hiding type constructors can allow for more abstract code as all construction must be done through factories. Abstract types cause 2 notable restrictions:
- No access to type constructors (type.Just would be undefined but type.Maybe would be available)
- No access to destructuring against constructor types, except inside builder context.
var t = type;tJust === undefined; // truetMaybedestructure === undefined; // truet = t;
Available from npm:
npm install singularity
Or available in single compressed artifact from releases (good for web usage).