parser for types + start moving all types to separate modules
This commit is contained in:
parent
8eec5b9239
commit
1d826ea8d4
11 changed files with 277 additions and 88 deletions
|
|
@ -3,52 +3,8 @@
|
|||
// A Product-type always has only two fields, called "left" and "right".
|
||||
// Product-types of more fields (called Structs) can be constructed by nesting Product-types.
|
||||
|
||||
import { makeGeneric } from "../generics/generics.js";
|
||||
import { GenericType, Type } from "../primitives/types.js";
|
||||
import { typedFnType } from "./types.js";
|
||||
import { prodType } from "./types.js";
|
||||
|
||||
// In JS, all products are encoded in the same way:
|
||||
export const newProduct = l => r => ({l, r});
|
||||
export const getLeft = product => product.l;
|
||||
export const getRight = product => product.r;
|
||||
|
||||
export const ModuleProduct = {l: [
|
||||
// binary type constructor
|
||||
// Type -> Type -> Type
|
||||
...typedFnType(prodType, fnType =>
|
||||
fnType
|
||||
(Type)
|
||||
(fnType
|
||||
(Type)
|
||||
(Type)
|
||||
)
|
||||
),
|
||||
|
||||
// a -> b -> (a, b)
|
||||
...typedFnType(newProduct, fnType =>
|
||||
makeGeneric((a, b) =>
|
||||
fnType
|
||||
(a)
|
||||
(fnType
|
||||
(b)
|
||||
(prodType(() => a)(() => b))
|
||||
)
|
||||
), GenericType),
|
||||
|
||||
// (a, b) -> a
|
||||
...typedFnType(getLeft, fnType =>
|
||||
makeGeneric((a, b) =>
|
||||
fnType
|
||||
(prodType(() => a)(() => b))
|
||||
(a)
|
||||
), GenericType),
|
||||
|
||||
// (a, b) -> b
|
||||
...typedFnType(getRight, fnType =>
|
||||
makeGeneric((a, b) =>
|
||||
fnType
|
||||
(prodType(() => a)(() => b))
|
||||
(b)
|
||||
), GenericType),
|
||||
]};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue