lotta progress
This commit is contained in:
parent
29d20b2273
commit
bc91d9bf39
27 changed files with 317 additions and 475 deletions
|
|
@ -1,18 +1,8 @@
|
|||
import { prodType } from "./product.js";
|
||||
import { Type } from "../metacircular.js";
|
||||
import { DefaultMap } from "../util.js";
|
||||
import { typedFnType } from "./function.js";
|
||||
import { prodType } from "./types.js";
|
||||
import { Type } from "../type.js";
|
||||
import { typedFnType } from "./types.js";
|
||||
import { makeGeneric } from "../generics/generics.js";
|
||||
|
||||
const symbolSum = Symbol("Sum");
|
||||
|
||||
const sumTypeRegistry = new DefaultMap(leftType => new DefaultMap(rightType => ({
|
||||
symbol: symbolSum,
|
||||
params: [leftType, rightType],
|
||||
})));
|
||||
|
||||
// type constructor
|
||||
export const sumType = leftType => rightType => sumTypeRegistry.getdefault(leftType, true).getdefault(rightType, true);
|
||||
import { sumType } from "./types.js";
|
||||
|
||||
const constructorLeft = left => ({variant: "L", value: left });
|
||||
const constructorRight = right => ({variant: "R", value: right});
|
||||
|
|
@ -26,35 +16,42 @@ const match = sum => handlers => sum.variant === "L"
|
|||
export const ModuleSum = {l:[
|
||||
// binary type constructor
|
||||
// Type -> Type -> Type
|
||||
...typedFnType(sumType, fnType => fnType
|
||||
(Type)
|
||||
(fnType
|
||||
(Type)
|
||||
...typedFnType(sumType, fnType =>
|
||||
fnType
|
||||
(Type)
|
||||
(fnType
|
||||
(Type)
|
||||
(Type)
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// a -> a | b
|
||||
...typedFnType(constructorLeft, fnType => makeGeneric((a, b) => fnType
|
||||
(a)
|
||||
(sumType(a)(b))
|
||||
)),
|
||||
...typedFnType(constructorLeft, fnType =>
|
||||
makeGeneric((a, b) =>
|
||||
fnType
|
||||
(a)
|
||||
(sumType(a)(b))
|
||||
)),
|
||||
|
||||
// b -> a | b
|
||||
...typedFnType(constructorRight, fnType => makeGeneric((a, b) => fnType
|
||||
(b)
|
||||
(sumType(a)(b))
|
||||
)),
|
||||
...typedFnType(constructorRight, fnType =>
|
||||
makeGeneric((a, b) =>
|
||||
fnType
|
||||
(b)
|
||||
(sumType(a)(b))
|
||||
)),
|
||||
|
||||
// a | b -> (a -> c, b-> c) -> c
|
||||
...typedFnType(match, fnType => makeGeneric((a, b, c) => fnType
|
||||
(sumType(a)(b))
|
||||
(fnType
|
||||
(prodType
|
||||
(fnType(a)(c))
|
||||
(fnType(b)(c))
|
||||
)
|
||||
(c)
|
||||
)
|
||||
)),
|
||||
...typedFnType(match, fnType =>
|
||||
makeGeneric((a, b, c) =>
|
||||
fnType
|
||||
(sumType(a)(b))
|
||||
(fnType
|
||||
(prodType
|
||||
(fnType(a)(c))
|
||||
(fnType(b)(c))
|
||||
)
|
||||
(c)
|
||||
)
|
||||
)),
|
||||
]};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue