use newDynamic() everywhere instead of { i: ... , t: ... }
This commit is contained in:
parent
34d06aa82a
commit
e1a2139cb4
22 changed files with 141 additions and 124 deletions
|
|
@ -16,15 +16,15 @@ const mkType = makeTypeParser({
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ModulePointNominal = [
|
export const ModulePointNominal = [
|
||||||
{i: PointCartesian2D , t: Type},
|
newDynamic(PointCartesian2D )(Type),
|
||||||
{i: PointPolar2D , t: Type},
|
newDynamic(PointPolar2D )(Type),
|
||||||
|
|
||||||
{i: examplePoint , t: PointCartesian2D},
|
newDynamic(examplePoint )(PointCartesian2D),
|
||||||
|
|
||||||
{i: cart2polar, t: mkType("PointCartesian2D -> PointPolar2D")},
|
newDynamic(cart2polar)(mkType("PointCartesian2D -> PointPolar2D")),
|
||||||
{i: polar2cart, t: mkType("PointPolar2D -> PointCartesian2D")},
|
newDynamic(polar2cart)(mkType("PointPolar2D -> PointCartesian2D")),
|
||||||
|
|
||||||
{i: translate, t: mkType("Double -> Double -> PointCartesian2D")},
|
newDynamic(translate)(mkType("Double -> Double -> PointCartesian2D")),
|
||||||
{i: rotate , t: mkType("Double -> PointPolar2D -> PointPolar2D")},
|
newDynamic(rotate )(mkType("Double -> PointPolar2D -> PointPolar2D")),
|
||||||
{i: scale , t: mkType("Double -> PointPolar2D -> PointPolar2D")},
|
newDynamic(scale )(mkType("Double -> PointPolar2D -> PointPolar2D")),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -57,20 +57,20 @@ const mkType = makeTypeParser({
|
||||||
});
|
});
|
||||||
|
|
||||||
const ModuleConversions = [
|
const ModuleConversions = [
|
||||||
{ i: NPoint2DCartesian , t: mkType("NPoint2DCartesian") },
|
newDynamic(NPoint2DCartesian )(mkType("NPoint2DCartesian") ),
|
||||||
{ i: NPoint2DPolar , t: mkType("NPoint2DPolar") },
|
newDynamic(NPoint2DPolar )(mkType("NPoint2DPolar") ),
|
||||||
{ i: cart2polar , t: mkType("NPoint2DCartesian -> NPoint2DPolar") },
|
newDynamic(cart2polar )(mkType("NPoint2DCartesian -> NPoint2DPolar") ),
|
||||||
{ i: polar2cart , t: mkType("NPoint2DPolar -> NPoint2DCartesian") },
|
newDynamic(polar2cart )(mkType("NPoint2DPolar -> NPoint2DCartesian") ),
|
||||||
];
|
];
|
||||||
|
|
||||||
const examplePointCart = newCartesian(1)(2);
|
const examplePointCart = newCartesian(1)(2);
|
||||||
const examplePointPolar = newPolar(0)(5);
|
const examplePointPolar = newPolar(0)(5);
|
||||||
|
|
||||||
const ModuleExamples = [
|
const ModuleExamples = [
|
||||||
{ i: examplePointCart , t: SPoint2DCartesian },
|
newDynamic(examplePointCart )(SPoint2DCartesian ),
|
||||||
{ i: examplePointCart , t: NPoint2DCartesian },
|
newDynamic(examplePointCart )(NPoint2DCartesian ),
|
||||||
{ i: examplePointPolar , t: SPoint2DPolar },
|
newDynamic(examplePointPolar )(SPoint2DPolar ),
|
||||||
{ i: examplePointPolar , t: NPoint2DPolar },
|
newDynamic(examplePointPolar )(NPoint2DPolar ),
|
||||||
];
|
];
|
||||||
|
|
||||||
export const ModuleAll = [
|
export const ModuleAll = [
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,6 @@ import { compareDynamic, makeCompareFn } from "./dynamic.js";
|
||||||
const mkType = getDefaultTypeParser();
|
const mkType = getDefaultTypeParser();
|
||||||
|
|
||||||
export const ModuleCompareDynamic = [
|
export const ModuleCompareDynamic = [
|
||||||
{i: makeCompareFn , t: mkType("Type -> a -> a -> Int")},
|
newDynamic(makeCompareFn )(mkType("Type -> a -> a -> Int")),
|
||||||
{i: compareDynamic, t: mkType("Dynamic -> Dynamic -> Int")},
|
newDynamic(compareDynamic)(mkType("Dynamic -> Dynamic -> Int")),
|
||||||
];
|
];
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
import { getDefaultTypeParser } from "../parser/type_parser.js";
|
import { getDefaultTypeParser } from "../parser/type_parser.js";
|
||||||
|
import { newDynamic } from "../primitives/dynamic.js";
|
||||||
import { compareBools, compareNumbers, compareSymbols, compareUnits } from "./primitives.js";
|
import { compareBools, compareNumbers, compareSymbols, compareUnits } from "./primitives.js";
|
||||||
|
|
||||||
const mkType = getDefaultTypeParser();
|
const mkType = getDefaultTypeParser();
|
||||||
|
|
||||||
export const ModuleComparePrimitives = [
|
export const ModuleComparePrimitives = [
|
||||||
{i: compareNumbers, t: mkType("Double -> Double -> Int")},
|
newDynamic(compareNumbers)(mkType("Double -> Double -> Int")),
|
||||||
{i: compareBools , t: mkType("Bool -> Bool -> Int")},
|
newDynamic(compareBools )(mkType("Bool -> Bool -> Int")),
|
||||||
{i: compareUnits , t: mkType("Unit -> Unit -> Int")},
|
newDynamic(compareUnits )(mkType("Unit -> Unit -> Int")),
|
||||||
{i: compareSymbols, t: mkType("UUID -> UUID -> Int")},
|
newDynamic(compareSymbols)(mkType("UUID -> UUID -> Int")),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,17 @@
|
||||||
import { getDefaultTypeParser } from "../parser/type_parser.js";
|
import { getDefaultTypeParser } from "../parser/type_parser.js";
|
||||||
|
import { newDynamic } from "../primitives/dynamic.js";
|
||||||
import { compareDicts, compareLists, compareProducts, compareSets, compareSums } from "./structures.js";
|
import { compareDicts, compareLists, compareProducts, compareSets, compareSums } from "./structures.js";
|
||||||
|
|
||||||
const mkType = getDefaultTypeParser();
|
const mkType = getDefaultTypeParser();
|
||||||
|
|
||||||
export const ModuleCompareStructures = [
|
export const ModuleCompareStructures = [
|
||||||
{i: compareLists, t: mkType("(a -> a -> Int) -> [a] -> [a] -> Int")},
|
newDynamic(compareLists)(mkType("(a -> a -> Int) -> [a] -> [a] -> Int")),
|
||||||
|
|
||||||
{i: compareProducts, t: mkType("(a -> a -> Int) -> (b -> b -> Int) -> (a*b) -> (a*b) -> Int")},
|
newDynamic(compareProducts)(mkType("(a -> a -> Int) -> (b -> b -> Int) -> (a*b) -> (a*b) -> Int")),
|
||||||
|
|
||||||
{i: compareSums, t: mkType("(a -> a -> Int) -> (b -> b -> Int) -> (a+b) -> (a+b) -> Int")},
|
newDynamic(compareSums)(mkType("(a -> a -> Int) -> (b -> b -> Int) -> (a+b) -> (a+b) -> Int")),
|
||||||
|
|
||||||
{i: compareSets, t: mkType("(a -> a -> Int) -> {a} -> {a} -> Int")},
|
newDynamic(compareSets)(mkType("(a -> a -> Int) -> {a} -> {a} -> Int")),
|
||||||
|
|
||||||
{i: compareDicts, t: mkType("(a -> a -> Int) -> (b -> b-> Int) -> (a => b) -> (a => b) -> Int")}
|
newDynamic(compareDicts)(mkType("(a -> a -> Int) -> (b -> b-> Int) -> (a => b) -> (a => b) -> Int"))
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
import { getDefaultTypeParser } from "../parser/type_parser.js";
|
import { getDefaultTypeParser } from "../parser/type_parser.js";
|
||||||
|
import { newDynamic } from "../primitives/dynamic.js";
|
||||||
import { compareTypes } from "./type.js";
|
import { compareTypes } from "./type.js";
|
||||||
|
|
||||||
const mkType = getDefaultTypeParser();
|
const mkType = getDefaultTypeParser();
|
||||||
|
|
||||||
export const ModuleCompareTypes = [
|
export const ModuleCompareTypes = [
|
||||||
{i: compareTypes, t: mkType("Type -> Type -> Int")},
|
newDynamic(compareTypes)(mkType("Type -> Type -> Int")),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,5 @@ const mkType = getDefaultTypeParser();
|
||||||
|
|
||||||
export const ModuleTypeConstructor = [
|
export const ModuleTypeConstructor = [
|
||||||
// Problem: number of parameters of returned function depends on the 'Int' parameter...
|
// Problem: number of parameters of returned function depends on the 'Int' parameter...
|
||||||
// {i: makeTypeConstructor, t: mkType("UUID -> Int -> ??")}
|
// newDynamic(makeTypeConstructor)(mkType("UUID -> Int -> ??"))
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import { getSymbol } from "../primitives/type.js";
|
||||||
import { TYPE_VARS } from "../primitives/typevars.js";
|
import { TYPE_VARS } from "../primitives/typevars.js";
|
||||||
import { dictType, fnType, lsType, prodType, sumType } from "../structures/type_constructors.types.js";
|
import { dictType, fnType, lsType, prodType, sumType } from "../structures/type_constructors.types.js";
|
||||||
import { setType } from "../structures/type_constructors.types.js";
|
import { setType } from "../structures/type_constructors.types.js";
|
||||||
|
import { prettyT } from "../util/pretty.js";
|
||||||
|
|
||||||
// A very stupid little parser, that can only parse:
|
// A very stupid little parser, that can only parse:
|
||||||
// - primitives => simply maps onto types.
|
// - primitives => simply maps onto types.
|
||||||
|
|
@ -126,12 +127,12 @@ export const makeTypeParser = ({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const parseGroup = (tokensInGroup, fn, labels, label) => {
|
const parseGroup = (expr, tokensInGroup, fn, labels, label) => {
|
||||||
// console.log('parseGroup ', tokensInGroup, fn);
|
// console.log('parseGroup ', tokensInGroup, fn);
|
||||||
return (fn === null)
|
return (fn === null)
|
||||||
? __parse(tokensInGroup, labels, label)
|
? __parse(expr, tokensInGroup, labels, label)
|
||||||
: fn(self => {
|
: fn(self => {
|
||||||
return __parse(tokensInGroup, extendLabels(labels, label, self));
|
return __parse(expr, tokensInGroup, extendLabels(labels, label, self));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,7 +140,7 @@ export const makeTypeParser = ({
|
||||||
return (label === null) ? labels : new Map([...labels, [label, self]])
|
return (label === null) ? labels : new Map([...labels, [label, self]])
|
||||||
};
|
};
|
||||||
|
|
||||||
const __parse = (tokens, labels = new Map(), label = null) => {
|
const __parse = (expr, tokens, labels = new Map(), label = null) => {
|
||||||
// console.log('parse ', tokens);
|
// console.log('parse ', tokens);
|
||||||
if (tokens[0].startsWith('#')) {
|
if (tokens[0].startsWith('#')) {
|
||||||
if (labels.has(tokens[0])) {
|
if (labels.has(tokens[0])) {
|
||||||
|
|
@ -147,7 +148,7 @@ export const makeTypeParser = ({
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// pass label and parse 'rest'
|
// pass label and parse 'rest'
|
||||||
return __parse(tokens.slice(1), labels, tokens[0]);
|
return __parse(expr, tokens.slice(1), labels, tokens[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tokens.length === 1) {
|
if (tokens.length === 1) {
|
||||||
|
|
@ -156,26 +157,28 @@ export const makeTypeParser = ({
|
||||||
else {
|
else {
|
||||||
const [lhsTokens, fnGrp, rest] = consumeGroup(tokens);
|
const [lhsTokens, fnGrp, rest] = consumeGroup(tokens);
|
||||||
if (rest.length === 0) {
|
if (rest.length === 0) {
|
||||||
return parseGroup(lhsTokens, fnGrp, labels, label);
|
return parseGroup(expr, lhsTokens, fnGrp, labels, label);
|
||||||
}
|
}
|
||||||
const [operator, ...rhsTokens] = rest;
|
const [operator, ...rhsTokens] = rest;
|
||||||
for (const [operatorChar, fn] of infixOperators) {
|
for (const [operatorChar, fn] of infixOperators) {
|
||||||
if (operator === operatorChar) {
|
if (operator === operatorChar) {
|
||||||
return fn
|
return fn
|
||||||
(self => {
|
(self => {
|
||||||
return parseGroup(lhsTokens, fnGrp, extendLabels(labels, label, self));
|
return parseGroup(expr, lhsTokens, fnGrp, extendLabels(labels, label, self));
|
||||||
})(self => {
|
})(self => {
|
||||||
return __parse(rhsTokens, extendLabels(labels, label, self));
|
return __parse(expr, rhsTokens, extendLabels(labels, label, self));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Error("unknown operator: "+operator)
|
throw new Error("unknown operator: "+operator+" in expression "+expr)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const parse = expr => {
|
const parse = expr => {
|
||||||
const tokens = tokenize(expr);
|
const tokens = tokenize(expr);
|
||||||
return __parse(tokens);
|
const parsed = __parse(expr, tokens);
|
||||||
|
prettyT(parsed); // force evaluation
|
||||||
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parse;
|
return parse;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,6 @@ const mkType = getDefaultTypeParser();
|
||||||
|
|
||||||
export const ModuleDouble = [
|
export const ModuleDouble = [
|
||||||
newDynamic(addDouble)(mkType("Double -> Double -> Double")),
|
newDynamic(addDouble)(mkType("Double -> Double -> Double")),
|
||||||
{ i: mulDouble, t: mkType("Double -> Double -> Double") },
|
newDynamic(mulDouble)(mkType("Double -> Double -> Double") ),
|
||||||
{ i: eqDouble, t: mkType("Double -> Double -> Bool") },
|
newDynamic(eqDouble)(mkType("Double -> Double -> Bool") ),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@ import { apply, getInst, getType, newDynamic } from "./dynamic.js";
|
||||||
const mkType = getDefaultTypeParser();
|
const mkType = getDefaultTypeParser();
|
||||||
|
|
||||||
export const ModuleDynamic = [
|
export const ModuleDynamic = [
|
||||||
{ i: newDynamic, t: mkType("a -> Type -> Dynamic")},
|
newDynamic(newDynamic)(mkType("a -> Type -> Dynamic")),
|
||||||
|
|
||||||
// allows us to (unsafely) cast the result to the specific type...
|
// allows us to (unsafely) cast the result to the specific type...
|
||||||
// (not sure if this is the right way to go)
|
// (not sure if this is the right way to go)
|
||||||
{ i: getInst, t: mkType("Dynamic -> a") },
|
newDynamic(getInst)(mkType("Dynamic -> a") ),
|
||||||
|
|
||||||
{ i: getType, t: mkType("Dynamic -> Type") },
|
newDynamic(getType)(mkType("Dynamic -> Type") ),
|
||||||
|
|
||||||
{ i: apply, t: mkType("Dynamic -> Dynamic -> Dynamic") },
|
newDynamic(apply)(mkType("Dynamic -> Dynamic -> Dynamic") ),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
import { getDefaultTypeParser }from "../parser/type_parser.js";
|
import { getDefaultTypeParser }from "../parser/type_parser.js";
|
||||||
|
import { newDynamic } from "./dynamic.js";
|
||||||
import { addInt, eqInt, mulInt } from "./int.js";
|
import { addInt, eqInt, mulInt } from "./int.js";
|
||||||
|
|
||||||
const mkType = getDefaultTypeParser();
|
const mkType = getDefaultTypeParser();
|
||||||
|
|
||||||
export const ModuleInt = [
|
export const ModuleInt = [
|
||||||
{ i: addInt, t: mkType("Int -> Int -> Int") },
|
newDynamic(addInt)(mkType("Int -> Int -> Int") ),
|
||||||
{ i: mulInt, t: mkType("Int -> Int -> Int") },
|
newDynamic(mulInt)(mkType("Int -> Int -> Int") ),
|
||||||
{ i: eqInt, t: mkType("Int -> Int -> Bool") },
|
newDynamic(eqInt)(mkType("Int -> Int -> Bool") ),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,30 @@
|
||||||
|
import { newDynamic } from "./dynamic.js";
|
||||||
import { SymbolInt, UUID, SymbolBool, SymbolDouble, SymbolByte, SymbolChar, SymbolUnit, SymbolBottom, SymbolUUID, SymbolType, SymbolTop, Type, Int, Bool, Double, Byte, Char, Unit, Bottom, Top, SymbolDynamic, Dynamic } from "./primitive_types.js";
|
import { SymbolInt, UUID, SymbolBool, SymbolDouble, SymbolByte, SymbolChar, SymbolUnit, SymbolBottom, SymbolUUID, SymbolType, SymbolTop, Type, Int, Bool, Double, Byte, Char, Unit, Bottom, Top, SymbolDynamic, Dynamic } from "./primitive_types.js";
|
||||||
|
|
||||||
export const ModulePrimitiveSymbols = [
|
export const ModulePrimitiveSymbols = [
|
||||||
{ i: SymbolInt , t: UUID },
|
newDynamic(SymbolInt )(UUID ),
|
||||||
{ i: SymbolBool , t: UUID },
|
newDynamic(SymbolBool )(UUID ),
|
||||||
{ i: SymbolDouble , t: UUID },
|
newDynamic(SymbolDouble )(UUID ),
|
||||||
{ i: SymbolByte , t: UUID },
|
newDynamic(SymbolByte )(UUID ),
|
||||||
{ i: SymbolChar , t: UUID },
|
newDynamic(SymbolChar )(UUID ),
|
||||||
{ i: SymbolUnit , t: UUID },
|
newDynamic(SymbolUnit )(UUID ),
|
||||||
{ i: SymbolBottom , t: UUID },
|
newDynamic(SymbolBottom )(UUID ),
|
||||||
{ i: SymbolUUID , t: UUID },
|
newDynamic(SymbolUUID )(UUID ),
|
||||||
{ i: SymbolType , t: UUID },
|
newDynamic(SymbolType )(UUID ),
|
||||||
{ i: SymbolTop , t: UUID },
|
newDynamic(SymbolTop )(UUID ),
|
||||||
{ i: SymbolDynamic , t: UUID },
|
newDynamic(SymbolDynamic )(UUID ),
|
||||||
];
|
];
|
||||||
|
|
||||||
export const ModulePrimitiveTypes = [
|
export const ModulePrimitiveTypes = [
|
||||||
{ i: Int , t: Type },
|
newDynamic(Int )(Type ),
|
||||||
{ i: Bool , t: Type },
|
newDynamic(Bool )(Type ),
|
||||||
{ i: Double , t: Type },
|
newDynamic(Double )(Type ),
|
||||||
{ i: Byte , t: Type },
|
newDynamic(Byte )(Type ),
|
||||||
{ i: Char , t: Type },
|
newDynamic(Char )(Type ),
|
||||||
{ i: Unit , t: Type },
|
newDynamic(Unit )(Type ),
|
||||||
{ i: Bottom , t: Type },
|
newDynamic(Bottom )(Type ),
|
||||||
{ i: UUID , t: Type },
|
newDynamic(UUID )(Type ),
|
||||||
{ i: Type , t: Type },
|
newDynamic(Type )(Type ),
|
||||||
{ i: Top , t: Type },
|
newDynamic(Top )(Type ),
|
||||||
{ i: Dynamic , t: Type },
|
newDynamic(Dynamic )(Type ),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import { getDefaultTypeParser } from "../parser/type_parser.js"
|
import { getDefaultTypeParser } from "../parser/type_parser.js"
|
||||||
|
import { newDynamic } from "./dynamic.js";
|
||||||
import { eqSymbol, getHumanReadableName } from "./symbol.js";
|
import { eqSymbol, getHumanReadableName } from "./symbol.js";
|
||||||
|
|
||||||
const mkType = getDefaultTypeParser();
|
const mkType = getDefaultTypeParser();
|
||||||
|
|
||||||
export const ModuleSymbol = [
|
export const ModuleSymbol = [
|
||||||
{ i: getHumanReadableName, t: mkType("UUID -> String")},
|
newDynamic(getHumanReadableName)(mkType("UUID -> String")),
|
||||||
{ i: eqSymbol, t: mkType("UUID -> UUID -> Bool")},
|
newDynamic(eqSymbol)(mkType("UUID -> UUID -> Bool")),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
// a module is just a set of typed objects
|
// a module is just a set of typed objects
|
||||||
|
|
||||||
import { getDefaultTypeParser } from "../parser/type_parser.js";
|
import { getDefaultTypeParser } from "../parser/type_parser.js";
|
||||||
|
import { newDynamic } from "./dynamic.js";
|
||||||
import { eqType, getParams, getSymbol } from "./type.js";
|
import { eqType, getParams, getSymbol } from "./type.js";
|
||||||
|
|
||||||
const mkType = getDefaultTypeParser();
|
const mkType = getDefaultTypeParser();
|
||||||
|
|
||||||
// each 'typed object' is implicitly an instance of TypeLink (defined below)
|
// each 'typed object' is implicitly an instance of TypeLink (defined below)
|
||||||
export const ModuleType = [
|
export const ModuleType = [
|
||||||
{i: eqType , t: mkType("Type -> Type -> Bool")},
|
newDynamic(eqType )(mkType("Type -> Type -> Bool")),
|
||||||
{i: getSymbol, t: mkType("Type -> UUID")},
|
newDynamic(getSymbol)(mkType("Type -> UUID")),
|
||||||
{i: getParams, t: mkType("Type -> [Type -> Type]")},
|
newDynamic(getParams)(mkType("Type -> [Type -> Type]")),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import { getDefaultTypeParser } from "../parser/type_parser.js";
|
import { getDefaultTypeParser } from "../parser/type_parser.js";
|
||||||
|
import { newDynamic } from "./dynamic.js";
|
||||||
import { eqUnit, unit } from "./unit.js";
|
import { eqUnit, unit } from "./unit.js";
|
||||||
|
|
||||||
const mkType = getDefaultTypeParser();
|
const mkType = getDefaultTypeParser();
|
||||||
|
|
||||||
export const ModuleUnit = [
|
export const ModuleUnit = [
|
||||||
{i: unit , t: mkType("Unit")},
|
newDynamic(unit )(mkType("Unit")),
|
||||||
{i: eqUnit, t: mkType("Unit -> Unit -> Bool")},
|
newDynamic(eqUnit)(mkType("Unit -> Unit -> Bool")),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { makeTypeParser } from "../parser/type_parser.js";
|
import { makeTypeParser } from "../parser/type_parser.js";
|
||||||
import { makeTypeConstructor } from "../meta/type_constructor.js";
|
import { makeTypeConstructor } from "../meta/type_constructor.js";
|
||||||
import { emptyDict, first, has, last, length, read, remove, set } from "./dict.js";
|
import { emptyDict, first, has, last, length, read, remove, set } from "./dict.js";
|
||||||
|
import { newDynamic } from "../primitives/dynamic.js";
|
||||||
|
|
||||||
export const symbolDictIterator = 'DictIterator__d9d175b6bfd1283f00851a99787d0499';
|
export const symbolDictIterator = 'DictIterator__d9d175b6bfd1283f00851a99787d0499';
|
||||||
|
|
||||||
|
|
@ -12,12 +13,12 @@ const mkType = makeTypeParser({
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ModuleDict = [
|
export const ModuleDict = [
|
||||||
{ i: emptyDict , t: mkType("(a -> a -> Int) -> (a => b)") },
|
newDynamic(emptyDict )(mkType("(a -> a -> Int) -> (a => b)") ),
|
||||||
{ i: has , t: mkType("(a => b) -> a -> Bool")},
|
newDynamic(has )(mkType("(a => b) -> a -> Bool")),
|
||||||
{ i: set , t: mkType("(a => b) -> a -> b -> (a => b)")},
|
newDynamic(set )(mkType("(a => b) -> a -> b -> (a => b)")),
|
||||||
{ i: remove , t: mkType("(a => b) -> a -> (a => b)")},
|
newDynamic(remove )(mkType("(a => b) -> a -> (a => b)")),
|
||||||
{ i: length , t: mkType("(a => b) -> Int")},
|
newDynamic(length )(mkType("(a => b) -> Int")),
|
||||||
{ i: first , t: mkType("(a => b) -> (a |=>| b)")},
|
newDynamic(first )(mkType("(a => b) -> (a |=>| b)")),
|
||||||
{ i: last , t: mkType("(a => b) -> (a |=>| b)")},
|
newDynamic(last )(mkType("(a => b) -> (a |=>| b)")),
|
||||||
{ i: read , t: mkType("(a |=>| b) -> (Unit + ((a*b) * (a |=>| b)))")},
|
newDynamic(read )(mkType("(a |=>| b) -> (Unit + ((a*b) * (a |=>| b)))")),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
import { getDefaultTypeParser }from "../parser/type_parser.js";
|
import { getDefaultTypeParser }from "../parser/type_parser.js";
|
||||||
|
import { newDynamic } from "../primitives/dynamic.js";
|
||||||
import { emptyList, fold, get, length, map, pop, push, put } from "./list.js";
|
import { emptyList, fold, get, length, map, pop, push, put } from "./list.js";
|
||||||
|
|
||||||
const mkType = getDefaultTypeParser();
|
const mkType = getDefaultTypeParser();
|
||||||
|
|
||||||
export const ModuleList = [
|
export const ModuleList = [
|
||||||
{ i: emptyList, t: mkType("[a]")},
|
newDynamic(emptyList)(mkType("[a]")),
|
||||||
{ i: get , t: mkType("[a] -> Int -> a")},
|
newDynamic(get )(mkType("[a] -> Int -> a")),
|
||||||
{ i: put , t: mkType("[a] -> Int -> a -> [a]")},
|
newDynamic(put )(mkType("[a] -> Int -> a -> [a]")),
|
||||||
{ i: push , t: mkType("[a] -> a -> [a]")},
|
newDynamic(push )(mkType("[a] -> a -> [a]")),
|
||||||
{ i: pop , t: mkType("[a] -> a")},
|
newDynamic(pop )(mkType("[a] -> a")),
|
||||||
{ i: map , t: mkType("[a] -> (a -> b) -> [b]")},
|
newDynamic(map )(mkType("[a] -> (a -> b) -> [b]")),
|
||||||
{ i: length , t: mkType("[a] -> Int")},
|
newDynamic(length )(mkType("[a] -> Int")),
|
||||||
{ i: fold , t: mkType("[a] -> (b -> a -> b) -> b -> b")},
|
newDynamic(fold )(mkType("[a] -> (b -> a -> b) -> b -> b")),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
import { getDefaultTypeParser } from "../parser/type_parser.js";
|
import { getDefaultTypeParser } from "../parser/type_parser.js";
|
||||||
|
import { newDynamic } from "../primitives/dynamic.js";
|
||||||
import { newProduct, getLeft, getRight } from "./product.js";
|
import { newProduct, getLeft, getRight } from "./product.js";
|
||||||
|
|
||||||
const mkType = getDefaultTypeParser();
|
const mkType = getDefaultTypeParser();
|
||||||
|
|
||||||
export const ModuleProduct = [
|
export const ModuleProduct = [
|
||||||
{ i: newProduct, t: mkType("a -> b -> (a * b)") },
|
newDynamic(newProduct)(mkType("a -> b -> (a * b)") ),
|
||||||
{ i: getLeft , t: mkType("(a * b) -> a" ) },
|
newDynamic(getLeft )(mkType("(a * b) -> a" ) ),
|
||||||
{ i: getRight , t: mkType("(a * b) -> b" ) },
|
newDynamic(getRight )(mkType("(a * b) -> b" ) ),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { makeTypeParser } from "../parser/type_parser.js";
|
import { makeTypeParser } from "../parser/type_parser.js";
|
||||||
import { makeTypeConstructor } from "../meta/type_constructor.js";
|
import { makeTypeConstructor } from "../meta/type_constructor.js";
|
||||||
import { emptySet, has, add, remove, length, first, read, last, fold } from "./set.js";
|
import { emptySet, has, add, remove, length, first, read, last, fold } from "./set.js";
|
||||||
|
import { newDynamic } from "../primitives/dynamic.js";
|
||||||
|
|
||||||
export const symbolSetIterator = 'SetIterator__f6b0ddd78ed41c58e5a442f2681da011';
|
export const symbolSetIterator = 'SetIterator__f6b0ddd78ed41c58e5a442f2681da011';
|
||||||
|
|
||||||
|
|
@ -11,13 +12,13 @@ const mkType = makeTypeParser({
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ModuleSet = [
|
export const ModuleSet = [
|
||||||
{ i: emptySet , t: mkType("(a -> a -> Int) -> {a}") },
|
newDynamic(emptySet )(mkType("(a -> a -> Int) -> {a}") ),
|
||||||
{ i: has , t: mkType("{a} -> a -> Bool")},
|
newDynamic(has )(mkType("{a} -> a -> Bool")),
|
||||||
{ i: add , t: mkType("{a} -> a -> {a}")},
|
newDynamic(add )(mkType("{a} -> a -> {a}")),
|
||||||
{ i: remove , t: mkType("{a} -> a -> {a}")},
|
newDynamic(remove )(mkType("{a} -> a -> {a}")),
|
||||||
{ i: length , t: mkType("{a} -> Int")},
|
newDynamic(length )(mkType("{a} -> Int")),
|
||||||
{ i: fold , t: mkType("{a} -> (b -> a -> b) -> b")},
|
newDynamic(fold )(mkType("{a} -> (b -> a -> b) -> b")),
|
||||||
{ i: first , t: mkType("{a} -> <a>")},
|
newDynamic(first )(mkType("{a} -> <a>")),
|
||||||
{ i: last , t: mkType("{a} -> <a>")},
|
newDynamic(last )(mkType("{a} -> <a>")),
|
||||||
{ i: read , t: mkType("<a> -> (Unit + (a * <a>))")},
|
newDynamic(read )(mkType("<a> -> (Unit + (a * <a>))")),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -57,10 +57,10 @@ export const makeModuleStruct = type => fields => {
|
||||||
const getterTypes = makeGettersTypes(fields);
|
const getterTypes = makeGettersTypes(fields);
|
||||||
const getters = makeGetters(fieldNames);
|
const getters = makeGetters(fieldNames);
|
||||||
const module = [
|
const module = [
|
||||||
// {i: type, t: Type},
|
// newDynamic(type)(Type),
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
{i: ctor, t: ctorType},
|
newDynamic(ctor)(ctorType),
|
||||||
|
|
||||||
// getters:
|
// getters:
|
||||||
...zip(getters, getterTypes)
|
...zip(getters, getterTypes)
|
||||||
|
|
@ -72,6 +72,6 @@ export const makeModuleStruct = type => fields => {
|
||||||
const mkType = getDefaultTypeParser();
|
const mkType = getDefaultTypeParser();
|
||||||
|
|
||||||
export const ModuleStruct = [
|
export const ModuleStruct = [
|
||||||
{i: structType, t: mkType("[String*Type] -> Type")},
|
newDynamic(structType)(mkType("[String*Type] -> Type")),
|
||||||
{i: makeModuleStruct, t: mkType("[String*Type] -> [Dynamic]")},
|
newDynamic(makeModuleStruct)(mkType("[String*Type] -> [Dynamic]")),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
import { getDefaultTypeParser }from "../parser/type_parser.js";
|
import { getDefaultTypeParser }from "../parser/type_parser.js";
|
||||||
|
import { newDynamic } from "../primitives/dynamic.js";
|
||||||
import { match, newLeft, newRight } from "./sum.js";
|
import { match, newLeft, newRight } from "./sum.js";
|
||||||
|
|
||||||
const mkType = getDefaultTypeParser();
|
const mkType = getDefaultTypeParser();
|
||||||
|
|
||||||
export const ModuleSum = [
|
export const ModuleSum = [
|
||||||
{ i: newLeft , t: mkType("a -> (a + b)") },
|
newDynamic(newLeft )(mkType("a -> (a + b)") ),
|
||||||
{ i: newRight , t: mkType("b -> (a + b)") },
|
newDynamic(newRight )(mkType("b -> (a + b)") ),
|
||||||
{ i: match , t: mkType("(a + b) -> (a -> c) -> (b -> c) -> c") },
|
newDynamic(match )(mkType("(a + b) -> (a -> c) -> (b -> c) -> c") ),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { makeTypeConstructor } from "../meta/type_constructor.js";
|
import { makeTypeConstructor } from "../meta/type_constructor.js";
|
||||||
|
import { newDynamic } from "../primitives/dynamic.js";
|
||||||
import { Type, UUID } from "../primitives/primitive_types.js";
|
import { Type, UUID } from "../primitives/primitive_types.js";
|
||||||
import { symbolDict, symbolFunction, symbolList, symbolProduct, symbolSet, symbolSum } from "./type_constructors.js";
|
import { symbolDict, symbolFunction, symbolList, symbolProduct, symbolSet, symbolSum } from "./type_constructors.js";
|
||||||
|
|
||||||
|
|
@ -10,12 +11,12 @@ export const setType = makeTypeConstructor(symbolSet)(1);
|
||||||
export const dictType = makeTypeConstructor(symbolDict)(2);
|
export const dictType = makeTypeConstructor(symbolDict)(2);
|
||||||
|
|
||||||
export const ModuleStructuralSymbols = [
|
export const ModuleStructuralSymbols = [
|
||||||
{ i: symbolSet , t: UUID },
|
newDynamic(symbolSet )(UUID ),
|
||||||
{ i: symbolList , t: UUID },
|
newDynamic(symbolList )(UUID ),
|
||||||
{ i: symbolProduct , t: UUID },
|
newDynamic(symbolProduct )(UUID ),
|
||||||
{ i: symbolSum , t: UUID },
|
newDynamic(symbolSum )(UUID ),
|
||||||
{ i: symbolDict , t: UUID },
|
newDynamic(symbolDict )(UUID ),
|
||||||
{ i: symbolFunction , t: UUID },
|
newDynamic(symbolFunction )(UUID ),
|
||||||
];
|
];
|
||||||
|
|
||||||
const unaryTypeConstructor = fnType(_ => Type)(_ => Type);
|
const unaryTypeConstructor = fnType(_ => Type)(_ => Type);
|
||||||
|
|
@ -23,10 +24,10 @@ const unaryTypeConstructor = fnType(_ => Type)(_ => Type);
|
||||||
const binaryTypeConstructor = fnType(_ => Type)(_ => unaryTypeConstructor);
|
const binaryTypeConstructor = fnType(_ => Type)(_ => unaryTypeConstructor);
|
||||||
|
|
||||||
export const ModuleTypeConstructors = [
|
export const ModuleTypeConstructors = [
|
||||||
{ i: setType , t: unaryTypeConstructor },
|
newDynamic(setType )(unaryTypeConstructor ),
|
||||||
{ i: lsType , t: unaryTypeConstructor },
|
newDynamic(lsType )(unaryTypeConstructor ),
|
||||||
{ i: prodType , t: binaryTypeConstructor },
|
newDynamic(prodType )(binaryTypeConstructor ),
|
||||||
{ i: sumType , t: binaryTypeConstructor },
|
newDynamic(sumType )(binaryTypeConstructor ),
|
||||||
{ i: dictType , t: binaryTypeConstructor },
|
newDynamic(dictType )(binaryTypeConstructor ),
|
||||||
{ i: fnType , t: binaryTypeConstructor },
|
newDynamic(fnType )(binaryTypeConstructor ),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue