refactor code: move everything from type_registry to "most appropriate" modules
This commit is contained in:
parent
4ca60784aa
commit
5283be608b
22 changed files with 160 additions and 164 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { fnType, lsType } from "../type_registry.js";
|
||||
import { lsType } from "./list_common.js";
|
||||
import { fnType } from "../metacircular.js";
|
||||
import {Type, Function} from "../metacircular.js";
|
||||
import { makeListModule } from "./list_common.js";
|
||||
import { Module } from "./list_types/module.js";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
import { fnType, lsType } from "../type_registry.js";
|
||||
import { fnType } from "../metacircular.js";
|
||||
import {Type, Function} from "../metacircular.js";
|
||||
import {Int, Byte} from "../primitives/symbols.js";
|
||||
import { DefaultMap } from "../util.js";
|
||||
|
||||
const listTypeRegistry = new DefaultMap(elementType => ({ listOf: elementType }));
|
||||
|
||||
// type constructor
|
||||
export const lsType = elementType => listTypeRegistry.getdefault(elementType, true);
|
||||
|
||||
// 'normal' implementation
|
||||
const emptyList = {l:[]};
|
||||
|
|
@ -66,4 +72,4 @@ export const makeListModule = elementType => {
|
|||
// {i: push , t: pushFnType},
|
||||
]};
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { makeListModule } from "../list_common.js";
|
||||
import { Typed } from "../../typed.js";
|
||||
import { lsType } from "../../type_registry.js";
|
||||
import { lsType } from "../list_common.js";
|
||||
|
||||
export const Module = lsType(Typed); // a Module is a list of Typeds
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Char } from "../../primitives/symbols.js";
|
||||
import { lsType } from "../../type_registry.js";
|
||||
import { lsType } from "../list_common.js";
|
||||
import { makeListModule } from "../list_common.js";
|
||||
|
||||
export const String = lsType(Char);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Type } from "../metacircular.js";
|
||||
import { String } from "../structures/list_types/string.js";
|
||||
import { prodType } from "../type_registry.js";
|
||||
import { prodType } from "./product.js";
|
||||
import { makeProductType } from "./product.js";
|
||||
|
||||
export const NominalType = prodType(String, Type);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
import { fnType, prodType } from "../type_registry.js";
|
||||
import { fnType } from "../metacircular.js";
|
||||
import { Function, Type } from "../metacircular.js";
|
||||
import { DefaultMap } from "../util.js";
|
||||
|
||||
const productTypeRegistry = new DefaultMap(leftType => new DefaultMap(rightType => ({ operator: "product", leftType, rightType })));
|
||||
|
||||
// type constructor
|
||||
export const prodType = (leftType, rightType) => productTypeRegistry.getdefault(leftType, true).getdefault(rightType, true);
|
||||
|
||||
// In JS, all products are encoded in the same way:
|
||||
const constructor = left => right => ({left, right});
|
||||
|
|
@ -28,4 +34,4 @@ export const makeProductType = (leftType, rightType) => {
|
|||
{i: constructorType , t: Function},
|
||||
{i: constructorBoundType, t: Function},
|
||||
]};
|
||||
};
|
||||
};
|
||||
|
|
@ -1,7 +1,14 @@
|
|||
import { fnType, prodType, sumType } from "../type_registry.js";
|
||||
import { sumType } from "../type_registry.js";
|
||||
import { prodType } from "./product.js";
|
||||
import { fnType } from "../metacircular.js";
|
||||
import { Function, Type } from "../metacircular.js";
|
||||
import { Module } from "./list_types/module.js";
|
||||
|
||||
const sumTypeRegistry = new DefaultMap(leftType => new DefaultMap(rightType => ({ operator: "sum", leftType, rightType })));
|
||||
|
||||
// type constructor
|
||||
export const sumType = (leftType, rightType) => sumTypeRegistry.getdefault(leftType, true).getdefault(rightType, true);
|
||||
|
||||
const constructorLeft = left => ({variant: "L", value: left });
|
||||
const constructorRight = right => ({variant: "R", value: right});
|
||||
|
||||
|
|
@ -43,4 +50,4 @@ export const makeSumType = (leftType, rightType) => {
|
|||
|
||||
{i: makeMatchFn, t: fnType({in: Type, out: Module})},
|
||||
]};
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue