restructure code a bit, add comparison functions for primitive types and composed types (needed to put values in sets)
This commit is contained in:
parent
3978f7f835
commit
8653bb99c6
12 changed files with 175 additions and 64 deletions
|
|
@ -1,17 +1,22 @@
|
|||
// Sum-type (also called: tagged union, disjoin union, variant type)
|
||||
// A Sum-type always has only two variants, called "left" and "right".
|
||||
// Sum-types of more variants (called Enums) can be constructed by nesting Sum-types.
|
||||
|
||||
import { prodType } from "./types.js";
|
||||
import { GenericType, Type } from "../primitives/types.js";
|
||||
import { typedFnType } from "./types.js";
|
||||
import { makeGeneric } from "../generics/generics.js";
|
||||
import { sumType } from "./types.js";
|
||||
|
||||
export const constructorLeft = left => ({variant: "L", value: left });
|
||||
export const constructorRight = right => ({variant: "R", value: right});
|
||||
export const constructorLeft = left => ({t: "L", v: left }); // 't': tag, 'v': value
|
||||
export const constructorRight = right => ({t: "R", v: right});
|
||||
|
||||
// signature:
|
||||
// sum-type -> (leftType -> resultType, rightType -> resultType) -> resultType
|
||||
export const match = sum => handlers => sum.variant === "L"
|
||||
? handlers.left(sum.value)
|
||||
: handlers.right(sum.value);
|
||||
export const match = sum => handlers =>
|
||||
sum.t === "L"
|
||||
? handlers.left(sum.v)
|
||||
: handlers.right(sum.v);
|
||||
|
||||
export const ModuleSum = {l:[
|
||||
// binary type constructor
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue