can auto-generate comparison functions for composed types
This commit is contained in:
parent
0b262daf7f
commit
4d1fb81492
6 changed files with 72 additions and 35 deletions
|
|
@ -8,7 +8,7 @@ import { getSymbol, makeTypeConstructor } from "../type_constructor.js";
|
|||
// The registry ensures that we never accidentally create more than one JS object for the same function type.
|
||||
// It is a cheap workaround for JS lacking customizable hash-functions and equality-testing-functions.
|
||||
// This same pattern is repeated throughout the code for all non-nullary type constructors (list, sum, product, ...)
|
||||
const symbolFunction = Symbol('Function');
|
||||
export const symbolFunction = Symbol('Function');
|
||||
export const fnType = makeTypeConstructor(symbolFunction)(2);
|
||||
|
||||
export const isFunction = type => getSymbol(type) === symbolFunction;
|
||||
|
|
@ -35,22 +35,22 @@ export const typedFnType = (instance, callback, typeOfType = Type) => {
|
|||
|
||||
// Sum type
|
||||
|
||||
const symbolSum = Symbol("Sum");
|
||||
export const symbolSum = Symbol("Sum");
|
||||
export const sumType = makeTypeConstructor(symbolSum)(2);
|
||||
|
||||
// Product type
|
||||
|
||||
const symbolProduct = Symbol("Product");
|
||||
export const symbolProduct = Symbol("Product");
|
||||
export const prodType = makeTypeConstructor(symbolProduct)(2);
|
||||
|
||||
// List type
|
||||
|
||||
const symbolList = Symbol('List');
|
||||
export const symbolList = Symbol('List');
|
||||
export const lsType = makeTypeConstructor(symbolList)(1);
|
||||
|
||||
// Set type
|
||||
|
||||
const symbolSet = Symbol('Set');
|
||||
export const symbolSet = Symbol('Set');
|
||||
export const setType = makeTypeConstructor(symbolSet)(1);
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue