diff --git a/examples/environment.js b/examples/environment.js
index d79748e..6ff41fa 100644
--- a/examples/environment.js
+++ b/examples/environment.js
@@ -3,17 +3,25 @@ import { ModuleStd } from "../lib/stdlib.js";
import { emptyDict, get, set } from "../lib/structures/dict.js";
import { emptySet, add } from "../lib/structures/set.js";
import { makeCompareFn } from "../lib/compare/dynamic.js"
+import { Type } from "../lib/primitives/primitive_types.js";
-// console.log(ModuleStd);
+console.log(ModuleStd);
+
+const addEntry = dict => i => t => {
+ const setOfInstances = get(dict)(t) || emptySet(makeCompareFn(t));
+ return set(dict)(t)(add(setOfInstances)(i));
+}
const typeDict = ModuleStd.reduce((typeDict, {i, t}) => {
try {
- const instances = get(typeDict)(t) || emptySet(makeCompareFn(t));
- return set(typeDict)(t)(add(instances)(i));
+ // add instance to type:
+ return addEntry(
+ addEntry(typeDict)(i)(t)
+ )(t)(Type);
} catch (e) {
console.log('warning:',e.message);
return typeDict;
}
}, emptyDict(compareTypes));
-console.log(typeDict);
\ No newline at end of file
+console.log(typeDict);
diff --git a/extra/point/nominal.types.js b/extra/point/nominal.types.js
index 06ff6dc..2820937 100644
--- a/extra/point/nominal.types.js
+++ b/extra/point/nominal.types.js
@@ -16,15 +16,15 @@ const mkType = makeTypeParser({
});
export const ModulePointNominal = [
- {i: PointCartesian2D , t: Type},
- {i: PointPolar2D , t: Type},
+ newDynamic(PointCartesian2D )(Type),
+ newDynamic(PointPolar2D )(Type),
- {i: examplePoint , t: PointCartesian2D},
+ newDynamic(examplePoint )(PointCartesian2D),
- {i: cart2polar, t: mkType("PointCartesian2D -> PointPolar2D")},
- {i: polar2cart, t: mkType("PointPolar2D -> PointCartesian2D")},
+ newDynamic(cart2polar)(mkType("PointCartesian2D -> PointPolar2D")),
+ newDynamic(polar2cart)(mkType("PointPolar2D -> PointCartesian2D")),
- {i: translate, t: mkType("Double -> Double -> PointCartesian2D")},
- {i: rotate , t: mkType("Double -> PointPolar2D -> PointPolar2D")},
- {i: scale , t: mkType("Double -> PointPolar2D -> PointPolar2D")},
+ newDynamic(translate)(mkType("Double -> Double -> PointCartesian2D")),
+ newDynamic(rotate )(mkType("Double -> PointPolar2D -> PointPolar2D")),
+ newDynamic(scale )(mkType("Double -> PointPolar2D -> PointPolar2D")),
];
diff --git a/extra/point/structural.types.js b/extra/point/structural.types.js
index 2904966..69b2dbc 100644
--- a/extra/point/structural.types.js
+++ b/extra/point/structural.types.js
@@ -57,20 +57,20 @@ const mkType = makeTypeParser({
});
const ModuleConversions = [
- { i: NPoint2DCartesian , t: mkType("NPoint2DCartesian") },
- { i: NPoint2DPolar , t: mkType("NPoint2DPolar") },
- { i: cart2polar , t: mkType("NPoint2DCartesian -> NPoint2DPolar") },
- { i: polar2cart , t: mkType("NPoint2DPolar -> NPoint2DCartesian") },
+ newDynamic(NPoint2DCartesian )(mkType("NPoint2DCartesian") ),
+ newDynamic(NPoint2DPolar )(mkType("NPoint2DPolar") ),
+ newDynamic(cart2polar )(mkType("NPoint2DCartesian -> NPoint2DPolar") ),
+ newDynamic(polar2cart )(mkType("NPoint2DPolar -> NPoint2DCartesian") ),
];
const examplePointCart = newCartesian(1)(2);
const examplePointPolar = newPolar(0)(5);
const ModuleExamples = [
- { i: examplePointCart , t: SPoint2DCartesian },
- { i: examplePointCart , t: NPoint2DCartesian },
- { i: examplePointPolar , t: SPoint2DPolar },
- { i: examplePointPolar , t: NPoint2DPolar },
+ newDynamic(examplePointCart )(SPoint2DCartesian ),
+ newDynamic(examplePointCart )(NPoint2DCartesian ),
+ newDynamic(examplePointPolar )(SPoint2DPolar ),
+ newDynamic(examplePointPolar )(NPoint2DPolar ),
];
export const ModuleAll = [
diff --git a/lib/compare/dynamic.types.js b/lib/compare/dynamic.types.js
index 157ef2d..9b6bcef 100644
--- a/lib/compare/dynamic.types.js
+++ b/lib/compare/dynamic.types.js
@@ -4,6 +4,6 @@ import { compareDynamic, makeCompareFn } from "./dynamic.js";
const mkType = getDefaultTypeParser();
export const ModuleCompareDynamic = [
- {i: makeCompareFn , t: mkType("Type -> a -> a -> Int")},
- {i: compareDynamic, t: mkType("Dynamic -> Dynamic -> Int")},
+ newDynamic(makeCompareFn )(mkType("Type -> a -> a -> Int")),
+ newDynamic(compareDynamic)(mkType("Dynamic -> Dynamic -> Int")),
];
\ No newline at end of file
diff --git a/lib/compare/primitives.types.js b/lib/compare/primitives.types.js
index 77a92cd..c3e45c9 100644
--- a/lib/compare/primitives.types.js
+++ b/lib/compare/primitives.types.js
@@ -1,11 +1,12 @@
import { getDefaultTypeParser } from "../parser/type_parser.js";
+import { newDynamic } from "../primitives/dynamic.js";
import { compareBools, compareNumbers, compareSymbols, compareUnits } from "./primitives.js";
const mkType = getDefaultTypeParser();
export const ModuleComparePrimitives = [
- {i: compareNumbers, t: mkType("Double -> Double -> Int")},
- {i: compareBools , t: mkType("Bool -> Bool -> Int")},
- {i: compareUnits , t: mkType("Unit -> Unit -> Int")},
- {i: compareSymbols, t: mkType("UUID -> UUID -> Int")},
+ newDynamic(compareNumbers)(mkType("Double -> Double -> Int")),
+ newDynamic(compareBools )(mkType("Bool -> Bool -> Int")),
+ newDynamic(compareUnits )(mkType("Unit -> Unit -> Int")),
+ newDynamic(compareSymbols)(mkType("UUID -> UUID -> Int")),
];
diff --git a/lib/compare/structures.types.js b/lib/compare/structures.types.js
index 199ae27..890bb94 100644
--- a/lib/compare/structures.types.js
+++ b/lib/compare/structures.types.js
@@ -1,16 +1,17 @@
import { getDefaultTypeParser } from "../parser/type_parser.js";
+import { newDynamic } from "../primitives/dynamic.js";
import { compareDicts, compareLists, compareProducts, compareSets, compareSums } from "./structures.js";
const mkType = getDefaultTypeParser();
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"))
];
diff --git a/lib/compare/type.types.js b/lib/compare/type.types.js
index ad11e3c..e7674ef 100644
--- a/lib/compare/type.types.js
+++ b/lib/compare/type.types.js
@@ -1,8 +1,9 @@
import { getDefaultTypeParser } from "../parser/type_parser.js";
+import { newDynamic } from "../primitives/dynamic.js";
import { compareTypes } from "./type.js";
const mkType = getDefaultTypeParser();
export const ModuleCompareTypes = [
- {i: compareTypes, t: mkType("Type -> Type -> Int")},
+ newDynamic(compareTypes)(mkType("Type -> Type -> Int")),
];
diff --git a/lib/meta/type_constructor.types.js b/lib/meta/type_constructor.types.js
index c16b03f..8c687b4 100644
--- a/lib/meta/type_constructor.types.js
+++ b/lib/meta/type_constructor.types.js
@@ -5,5 +5,5 @@ const mkType = getDefaultTypeParser();
export const ModuleTypeConstructor = [
// Problem: number of parameters of returned function depends on the 'Int' parameter...
- // {i: makeTypeConstructor, t: mkType("UUID -> Int -> ??")}
+ // newDynamic(makeTypeConstructor)(mkType("UUID -> Int -> ??"))
];
diff --git a/lib/parser/type_parser.js b/lib/parser/type_parser.js
index 0a35c45..40b47bc 100644
--- a/lib/parser/type_parser.js
+++ b/lib/parser/type_parser.js
@@ -7,6 +7,7 @@ import { getSymbol } from "../primitives/type.js";
import { TYPE_VARS } from "../primitives/typevars.js";
import { dictType, fnType, lsType, prodType, sumType } 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:
// - 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);
return (fn === null)
- ? __parse(tokensInGroup, labels, label)
+ ? __parse(expr, tokensInGroup, labels, label)
: 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]])
};
- const __parse = (tokens, labels = new Map(), label = null) => {
+ const __parse = (expr, tokens, labels = new Map(), label = null) => {
// console.log('parse ', tokens);
if (tokens[0].startsWith('#')) {
if (labels.has(tokens[0])) {
@@ -147,7 +148,7 @@ export const makeTypeParser = ({
}
else {
// 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) {
@@ -156,26 +157,28 @@ export const makeTypeParser = ({
else {
const [lhsTokens, fnGrp, rest] = consumeGroup(tokens);
if (rest.length === 0) {
- return parseGroup(lhsTokens, fnGrp, labels, label);
+ return parseGroup(expr, lhsTokens, fnGrp, labels, label);
}
const [operator, ...rhsTokens] = rest;
for (const [operatorChar, fn] of infixOperators) {
if (operator === operatorChar) {
return fn
(self => {
- return parseGroup(lhsTokens, fnGrp, extendLabels(labels, label, self));
+ return parseGroup(expr, lhsTokens, fnGrp, extendLabels(labels, label, 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 tokens = tokenize(expr);
- return __parse(tokens);
+ const parsed = __parse(expr, tokens);
+ prettyT(parsed); // force evaluation
+ return parsed;
}
return parse;
diff --git a/lib/primitives/double.types.js b/lib/primitives/double.types.js
index 6e64769..e0301a8 100644
--- a/lib/primitives/double.types.js
+++ b/lib/primitives/double.types.js
@@ -1,10 +1,11 @@
import { getDefaultTypeParser } from "../parser/type_parser.js";
import { addDouble, eqDouble, mulDouble } from "./double.js";
+import { newDynamic } from "./dynamic.js";
const mkType = getDefaultTypeParser();
export const ModuleDouble = [
- { i: addDouble, t: mkType("Double -> Double -> Double") },
- { i: mulDouble, t: mkType("Double -> Double -> Double") },
- { i: eqDouble, t: mkType("Double -> Double -> Bool") },
+ newDynamic(addDouble)(mkType("Double -> Double -> Double")),
+ newDynamic(mulDouble)(mkType("Double -> Double -> Double") ),
+ newDynamic(eqDouble)(mkType("Double -> Double -> Bool") ),
];
diff --git a/lib/primitives/dynamic.js b/lib/primitives/dynamic.js
index e00e67e..3ef2769 100644
--- a/lib/primitives/dynamic.js
+++ b/lib/primitives/dynamic.js
@@ -1,6 +1,14 @@
+import { inspect } from "node:util";
import { assignFn } from "../generics/generics.js";
-export const newDynamic = i => t => ({i, t});
+function inspectDynamic(_depth, options, inspect) {
+ return `${inspect(this.i, options)} :: ${inspect(this.t, options)}`;
+}
+
+export const newDynamic = i => t => ({
+ i, t,
+ [inspect.custom]: inspectDynamic,
+});
export const getInst = lnk => lnk.i;
export const getType = lnk => lnk.t;
diff --git a/lib/primitives/dynamic.types.js b/lib/primitives/dynamic.types.js
index c36af30..b3360a1 100644
--- a/lib/primitives/dynamic.types.js
+++ b/lib/primitives/dynamic.types.js
@@ -4,13 +4,13 @@ import { apply, getInst, getType, newDynamic } from "./dynamic.js";
const mkType = getDefaultTypeParser();
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...
// (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") ),
];
diff --git a/lib/primitives/int.types.js b/lib/primitives/int.types.js
index dd3a2b8..4946edf 100644
--- a/lib/primitives/int.types.js
+++ b/lib/primitives/int.types.js
@@ -1,10 +1,11 @@
import { getDefaultTypeParser }from "../parser/type_parser.js";
+import { newDynamic } from "./dynamic.js";
import { addInt, eqInt, mulInt } from "./int.js";
const mkType = getDefaultTypeParser();
export const ModuleInt = [
- { i: addInt, t: mkType("Int -> Int -> Int") },
- { i: mulInt, t: mkType("Int -> Int -> Int") },
- { i: eqInt, t: mkType("Int -> Int -> Bool") },
+ newDynamic(addInt)(mkType("Int -> Int -> Int") ),
+ newDynamic(mulInt)(mkType("Int -> Int -> Int") ),
+ newDynamic(eqInt)(mkType("Int -> Int -> Bool") ),
];
diff --git a/lib/primitives/primitive_types.types.js b/lib/primitives/primitive_types.types.js
index 6bc2bca..936247a 100644
--- a/lib/primitives/primitive_types.types.js
+++ b/lib/primitives/primitive_types.types.js
@@ -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";
export const ModulePrimitiveSymbols = [
- { i: SymbolInt , t: UUID },
- { i: SymbolBool , t: UUID },
- { i: SymbolDouble , t: UUID },
- { i: SymbolByte , t: UUID },
- { i: SymbolChar , t: UUID },
- { i: SymbolUnit , t: UUID },
- { i: SymbolBottom , t: UUID },
- { i: SymbolUUID , t: UUID },
- { i: SymbolType , t: UUID },
- { i: SymbolTop , t: UUID },
- { i: SymbolDynamic , t: UUID },
+ newDynamic(SymbolInt )(UUID ),
+ newDynamic(SymbolBool )(UUID ),
+ newDynamic(SymbolDouble )(UUID ),
+ newDynamic(SymbolByte )(UUID ),
+ newDynamic(SymbolChar )(UUID ),
+ newDynamic(SymbolUnit )(UUID ),
+ newDynamic(SymbolBottom )(UUID ),
+ newDynamic(SymbolUUID )(UUID ),
+ newDynamic(SymbolType )(UUID ),
+ newDynamic(SymbolTop )(UUID ),
+ newDynamic(SymbolDynamic )(UUID ),
];
export const ModulePrimitiveTypes = [
- { i: Int , t: Type },
- { i: Bool , t: Type },
- { i: Double , t: Type },
- { i: Byte , t: Type },
- { i: Char , t: Type },
- { i: Unit , t: Type },
- { i: Bottom , t: Type },
- { i: UUID , t: Type },
- { i: Type , t: Type },
- { i: Top , t: Type },
- { i: Dynamic , t: Type },
+ newDynamic(Int )(Type ),
+ newDynamic(Bool )(Type ),
+ newDynamic(Double )(Type ),
+ newDynamic(Byte )(Type ),
+ newDynamic(Char )(Type ),
+ newDynamic(Unit )(Type ),
+ newDynamic(Bottom )(Type ),
+ newDynamic(UUID )(Type ),
+ newDynamic(Type )(Type ),
+ newDynamic(Top )(Type ),
+ newDynamic(Dynamic )(Type ),
];
diff --git a/lib/primitives/symbol.types.js b/lib/primitives/symbol.types.js
index 31453c2..23ff8f8 100644
--- a/lib/primitives/symbol.types.js
+++ b/lib/primitives/symbol.types.js
@@ -1,9 +1,10 @@
import { getDefaultTypeParser } from "../parser/type_parser.js"
+import { newDynamic } from "./dynamic.js";
import { eqSymbol, getHumanReadableName } from "./symbol.js";
const mkType = getDefaultTypeParser();
export const ModuleSymbol = [
- { i: getHumanReadableName, t: mkType("UUID -> String")},
- { i: eqSymbol, t: mkType("UUID -> UUID -> Bool")},
+ newDynamic(getHumanReadableName)(mkType("UUID -> String")),
+ newDynamic(eqSymbol)(mkType("UUID -> UUID -> Bool")),
];
diff --git a/lib/primitives/type.types.js b/lib/primitives/type.types.js
index a840c79..20f6893 100644
--- a/lib/primitives/type.types.js
+++ b/lib/primitives/type.types.js
@@ -1,13 +1,14 @@
// a module is just a set of typed objects
import { getDefaultTypeParser } from "../parser/type_parser.js";
+import { newDynamic } from "./dynamic.js";
import { eqType, getParams, getSymbol } from "./type.js";
const mkType = getDefaultTypeParser();
// each 'typed object' is implicitly an instance of TypeLink (defined below)
export const ModuleType = [
- {i: eqType , t: mkType("Type -> Type -> Bool")},
- {i: getSymbol, t: mkType("Type -> UUID")},
- {i: getParams, t: mkType("Type -> [Type -> Type]")},
+ newDynamic(eqType )(mkType("Type -> Type -> Bool")),
+ newDynamic(getSymbol)(mkType("Type -> UUID")),
+ newDynamic(getParams)(mkType("Type -> [Type -> Type]")),
];
diff --git a/lib/primitives/unit.types.js b/lib/primitives/unit.types.js
index 33f64e5..664aba6 100644
--- a/lib/primitives/unit.types.js
+++ b/lib/primitives/unit.types.js
@@ -1,9 +1,10 @@
import { getDefaultTypeParser } from "../parser/type_parser.js";
+import { newDynamic } from "./dynamic.js";
import { eqUnit, unit } from "./unit.js";
const mkType = getDefaultTypeParser();
export const ModuleUnit = [
- {i: unit , t: mkType("Unit")},
- {i: eqUnit, t: mkType("Unit -> Unit -> Bool")},
+ newDynamic(unit )(mkType("Unit")),
+ newDynamic(eqUnit)(mkType("Unit -> Unit -> Bool")),
];
diff --git a/lib/structures/dict.types.js b/lib/structures/dict.types.js
index c27ff43..cfab95c 100644
--- a/lib/structures/dict.types.js
+++ b/lib/structures/dict.types.js
@@ -1,6 +1,7 @@
import { makeTypeParser } from "../parser/type_parser.js";
import { makeTypeConstructor } from "../meta/type_constructor.js";
import { emptyDict, first, has, last, length, read, remove, set } from "./dict.js";
+import { newDynamic } from "../primitives/dynamic.js";
export const symbolDictIterator = 'DictIterator__d9d175b6bfd1283f00851a99787d0499';
@@ -12,12 +13,12 @@ const mkType = makeTypeParser({
});
export const ModuleDict = [
- { i: emptyDict , t: mkType("(a -> a -> Int) -> (a => b)") },
- { i: has , t: mkType("(a => b) -> a -> Bool")},
- { i: set , t: mkType("(a => b) -> a -> b -> (a => b)")},
- { i: remove , t: mkType("(a => b) -> a -> (a => b)")},
- { i: length , t: mkType("(a => b) -> Int")},
- { i: first , t: mkType("(a => b) -> (a |=>| b)")},
- { i: last , t: mkType("(a => b) -> (a |=>| b)")},
- { i: read , t: mkType("(a |=>| b) -> (Unit + ((a*b) * (a |=>| b)))")},
+ newDynamic(emptyDict )(mkType("(a -> a -> Int) -> (a => b)") ),
+ newDynamic(has )(mkType("(a => b) -> a -> Bool")),
+ newDynamic(set )(mkType("(a => b) -> a -> b -> (a => b)")),
+ newDynamic(remove )(mkType("(a => b) -> a -> (a => b)")),
+ newDynamic(length )(mkType("(a => b) -> Int")),
+ newDynamic(first )(mkType("(a => b) -> (a |=>| b)")),
+ newDynamic(last )(mkType("(a => b) -> (a |=>| b)")),
+ newDynamic(read )(mkType("(a |=>| b) -> (Unit + ((a*b) * (a |=>| b)))")),
];
diff --git a/lib/structures/list.types.js b/lib/structures/list.types.js
index 8801276..6ccb965 100644
--- a/lib/structures/list.types.js
+++ b/lib/structures/list.types.js
@@ -1,15 +1,16 @@
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";
const mkType = getDefaultTypeParser();
export const ModuleList = [
- { i: emptyList, t: mkType("[a]")},
- { i: get , t: mkType("[a] -> Int -> a")},
- { i: put , t: mkType("[a] -> Int -> a -> [a]")},
- { i: push , t: mkType("[a] -> a -> [a]")},
- { i: pop , t: mkType("[a] -> a")},
- { i: map , t: mkType("[a] -> (a -> b) -> [b]")},
- { i: length , t: mkType("[a] -> Int")},
- { i: fold , t: mkType("[a] -> (b -> a -> b) -> b -> b")},
+ newDynamic(emptyList)(mkType("[a]")),
+ newDynamic(get )(mkType("[a] -> Int -> a")),
+ newDynamic(put )(mkType("[a] -> Int -> a -> [a]")),
+ newDynamic(push )(mkType("[a] -> a -> [a]")),
+ newDynamic(pop )(mkType("[a] -> a")),
+ newDynamic(map )(mkType("[a] -> (a -> b) -> [b]")),
+ newDynamic(length )(mkType("[a] -> Int")),
+ newDynamic(fold )(mkType("[a] -> (b -> a -> b) -> b -> b")),
];
diff --git a/lib/structures/product.types.js b/lib/structures/product.types.js
index 3e44a99..7489c3f 100644
--- a/lib/structures/product.types.js
+++ b/lib/structures/product.types.js
@@ -1,10 +1,11 @@
import { getDefaultTypeParser } from "../parser/type_parser.js";
+import { newDynamic } from "../primitives/dynamic.js";
import { newProduct, getLeft, getRight } from "./product.js";
const mkType = getDefaultTypeParser();
export const ModuleProduct = [
- { i: newProduct, t: mkType("a -> b -> (a * b)") },
- { i: getLeft , t: mkType("(a * b) -> a" ) },
- { i: getRight , t: mkType("(a * b) -> b" ) },
+ newDynamic(newProduct)(mkType("a -> b -> (a * b)") ),
+ newDynamic(getLeft )(mkType("(a * b) -> a" ) ),
+ newDynamic(getRight )(mkType("(a * b) -> b" ) ),
];
diff --git a/lib/structures/set.types.js b/lib/structures/set.types.js
index 82827a8..1f02388 100644
--- a/lib/structures/set.types.js
+++ b/lib/structures/set.types.js
@@ -1,6 +1,7 @@
import { makeTypeParser } from "../parser/type_parser.js";
import { makeTypeConstructor } from "../meta/type_constructor.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';
@@ -11,13 +12,13 @@ const mkType = makeTypeParser({
});
export const ModuleSet = [
- { i: emptySet , t: mkType("(a -> a -> Int) -> {a}") },
- { i: has , t: mkType("{a} -> a -> Bool")},
- { i: add , t: mkType("{a} -> a -> {a}")},
- { i: remove , t: mkType("{a} -> a -> {a}")},
- { i: length , t: mkType("{a} -> Int")},
- { i: fold , t: mkType("{a} -> (b -> a -> b) -> b")},
- { i: first , t: mkType("{a} -> ")},
- { i: last , t: mkType("{a} -> ")},
- { i: read , t: mkType(" -> (Unit + (a * ))")},
+ newDynamic(emptySet )(mkType("(a -> a -> Int) -> {a}") ),
+ newDynamic(has )(mkType("{a} -> a -> Bool")),
+ newDynamic(add )(mkType("{a} -> a -> {a}")),
+ newDynamic(remove )(mkType("{a} -> a -> {a}")),
+ newDynamic(length )(mkType("{a} -> Int")),
+ newDynamic(fold )(mkType("{a} -> (b -> a -> b) -> b")),
+ newDynamic(first )(mkType("{a} -> ")),
+ newDynamic(last )(mkType("{a} -> ")),
+ newDynamic(read )(mkType(" -> (Unit + (a * ))")),
];
diff --git a/lib/structures/struct.types.js b/lib/structures/struct.types.js
index 88b149c..209a4e0 100644
--- a/lib/structures/struct.types.js
+++ b/lib/structures/struct.types.js
@@ -57,10 +57,10 @@ export const makeModuleStruct = type => fields => {
const getterTypes = makeGettersTypes(fields);
const getters = makeGetters(fieldNames);
const module = [
- // {i: type, t: Type},
+ // newDynamic(type)(Type),
// constructor
- {i: ctor, t: ctorType},
+ newDynamic(ctor)(ctorType),
// getters:
...zip(getters, getterTypes)
@@ -72,6 +72,6 @@ export const makeModuleStruct = type => fields => {
const mkType = getDefaultTypeParser();
export const ModuleStruct = [
- {i: structType, t: mkType("[String*Type] -> Type")},
- {i: makeModuleStruct, t: mkType("[String*Type] -> [Dynamic]")},
+ newDynamic(structType)(mkType("[String*Type] -> Type")),
+ newDynamic(makeModuleStruct)(mkType("[String*Type] -> [Dynamic]")),
];
diff --git a/lib/structures/sum.types.js b/lib/structures/sum.types.js
index 38741e0..a9fd8ac 100644
--- a/lib/structures/sum.types.js
+++ b/lib/structures/sum.types.js
@@ -1,10 +1,11 @@
import { getDefaultTypeParser }from "../parser/type_parser.js";
+import { newDynamic } from "../primitives/dynamic.js";
import { match, newLeft, newRight } from "./sum.js";
const mkType = getDefaultTypeParser();
export const ModuleSum = [
- { i: newLeft , t: mkType("a -> (a + b)") },
- { i: newRight , t: mkType("b -> (a + b)") },
- { i: match , t: mkType("(a + b) -> (a -> c) -> (b -> c) -> c") },
+ newDynamic(newLeft )(mkType("a -> (a + b)") ),
+ newDynamic(newRight )(mkType("b -> (a + b)") ),
+ newDynamic(match )(mkType("(a + b) -> (a -> c) -> (b -> c) -> c") ),
];
diff --git a/lib/structures/type_constructors.types.js b/lib/structures/type_constructors.types.js
index d0acf22..bbc7b85 100644
--- a/lib/structures/type_constructors.types.js
+++ b/lib/structures/type_constructors.types.js
@@ -1,4 +1,5 @@
import { makeTypeConstructor } from "../meta/type_constructor.js";
+import { newDynamic } from "../primitives/dynamic.js";
import { Type, UUID } from "../primitives/primitive_types.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 ModuleStructuralSymbols = [
- { i: symbolSet , t: UUID },
- { i: symbolList , t: UUID },
- { i: symbolProduct , t: UUID },
- { i: symbolSum , t: UUID },
- { i: symbolDict , t: UUID },
- { i: symbolFunction , t: UUID },
+ newDynamic(symbolSet )(UUID ),
+ newDynamic(symbolList )(UUID ),
+ newDynamic(symbolProduct )(UUID ),
+ newDynamic(symbolSum )(UUID ),
+ newDynamic(symbolDict )(UUID ),
+ newDynamic(symbolFunction )(UUID ),
];
const unaryTypeConstructor = fnType(_ => Type)(_ => Type);
@@ -23,10 +24,10 @@ const unaryTypeConstructor = fnType(_ => Type)(_ => Type);
const binaryTypeConstructor = fnType(_ => Type)(_ => unaryTypeConstructor);
export const ModuleTypeConstructors = [
- { i: setType , t: unaryTypeConstructor },
- { i: lsType , t: unaryTypeConstructor },
- { i: prodType , t: binaryTypeConstructor },
- { i: sumType , t: binaryTypeConstructor },
- { i: dictType , t: binaryTypeConstructor },
- { i: fnType , t: binaryTypeConstructor },
+ newDynamic(setType )(unaryTypeConstructor ),
+ newDynamic(lsType )(unaryTypeConstructor ),
+ newDynamic(prodType )(binaryTypeConstructor ),
+ newDynamic(sumType )(binaryTypeConstructor ),
+ newDynamic(dictType )(binaryTypeConstructor ),
+ newDynamic(fnType )(binaryTypeConstructor ),
];