Compare commits

..

No commits in common. "e1a2139cb43be0cb794a0ba24a7e7703df0fef90" and "4c394441b0ba589119a4c3d3c37ed41ef904627e" have entirely different histories.

24 changed files with 130 additions and 164 deletions

View file

@ -3,21 +3,13 @@ import { ModuleStd } from "../lib/stdlib.js";
import { emptyDict, get, set } from "../lib/structures/dict.js"; import { emptyDict, get, set } from "../lib/structures/dict.js";
import { emptySet, add } from "../lib/structures/set.js"; import { emptySet, add } from "../lib/structures/set.js";
import { makeCompareFn } from "../lib/compare/dynamic.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}) => { const typeDict = ModuleStd.reduce((typeDict, {i, t}) => {
try { try {
// add instance to type: const instances = get(typeDict)(t) || emptySet(makeCompareFn(t));
return addEntry( return set(typeDict)(t)(add(instances)(i));
addEntry(typeDict)(i)(t)
)(t)(Type);
} catch (e) { } catch (e) {
console.log('warning:',e.message); console.log('warning:',e.message);
return typeDict; return typeDict;

View file

@ -16,15 +16,15 @@ const mkType = makeTypeParser({
}); });
export const ModulePointNominal = [ export const ModulePointNominal = [
newDynamic(PointCartesian2D )(Type), {i: PointCartesian2D , t: Type},
newDynamic(PointPolar2D )(Type), {i: PointPolar2D , t: Type},
newDynamic(examplePoint )(PointCartesian2D), {i: examplePoint , t: PointCartesian2D},
newDynamic(cart2polar)(mkType("PointCartesian2D -> PointPolar2D")), {i: cart2polar, t: mkType("PointCartesian2D -> PointPolar2D")},
newDynamic(polar2cart)(mkType("PointPolar2D -> PointCartesian2D")), {i: polar2cart, t: mkType("PointPolar2D -> PointCartesian2D")},
newDynamic(translate)(mkType("Double -> Double -> PointCartesian2D")), {i: translate, t: mkType("Double -> Double -> PointCartesian2D")},
newDynamic(rotate )(mkType("Double -> PointPolar2D -> PointPolar2D")), {i: rotate , t: mkType("Double -> PointPolar2D -> PointPolar2D")},
newDynamic(scale )(mkType("Double -> PointPolar2D -> PointPolar2D")), {i: scale , t: mkType("Double -> PointPolar2D -> PointPolar2D")},
]; ];

View file

@ -57,20 +57,20 @@ const mkType = makeTypeParser({
}); });
const ModuleConversions = [ const ModuleConversions = [
newDynamic(NPoint2DCartesian )(mkType("NPoint2DCartesian") ), { i: NPoint2DCartesian , t: mkType("NPoint2DCartesian") },
newDynamic(NPoint2DPolar )(mkType("NPoint2DPolar") ), { i: NPoint2DPolar , t: mkType("NPoint2DPolar") },
newDynamic(cart2polar )(mkType("NPoint2DCartesian -> NPoint2DPolar") ), { i: cart2polar , t: mkType("NPoint2DCartesian -> NPoint2DPolar") },
newDynamic(polar2cart )(mkType("NPoint2DPolar -> NPoint2DCartesian") ), { i: polar2cart , t: 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 = [
newDynamic(examplePointCart )(SPoint2DCartesian ), { i: examplePointCart , t: SPoint2DCartesian },
newDynamic(examplePointCart )(NPoint2DCartesian ), { i: examplePointCart , t: NPoint2DCartesian },
newDynamic(examplePointPolar )(SPoint2DPolar ), { i: examplePointPolar , t: SPoint2DPolar },
newDynamic(examplePointPolar )(NPoint2DPolar ), { i: examplePointPolar , t: NPoint2DPolar },
]; ];
export const ModuleAll = [ export const ModuleAll = [

View file

@ -4,6 +4,6 @@ import { compareDynamic, makeCompareFn } from "./dynamic.js";
const mkType = getDefaultTypeParser(); const mkType = getDefaultTypeParser();
export const ModuleCompareDynamic = [ export const ModuleCompareDynamic = [
newDynamic(makeCompareFn )(mkType("Type -> a -> a -> Int")), {i: makeCompareFn , t: mkType("Type -> a -> a -> Int")},
newDynamic(compareDynamic)(mkType("Dynamic -> Dynamic -> Int")), {i: compareDynamic, t: mkType("Dynamic -> Dynamic -> Int")},
]; ];

View file

@ -1,12 +1,11 @@
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 = [
newDynamic(compareNumbers)(mkType("Double -> Double -> Int")), {i: compareNumbers, t: mkType("Double -> Double -> Int")},
newDynamic(compareBools )(mkType("Bool -> Bool -> Int")), {i: compareBools , t: mkType("Bool -> Bool -> Int")},
newDynamic(compareUnits )(mkType("Unit -> Unit -> Int")), {i: compareUnits , t: mkType("Unit -> Unit -> Int")},
newDynamic(compareSymbols)(mkType("UUID -> UUID -> Int")), {i: compareSymbols, t: mkType("UUID -> UUID -> Int")},
]; ];

View file

@ -1,17 +1,16 @@
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 = [
newDynamic(compareLists)(mkType("(a -> a -> Int) -> [a] -> [a] -> Int")), {i: compareLists, t: mkType("(a -> a -> Int) -> [a] -> [a] -> Int")},
newDynamic(compareProducts)(mkType("(a -> a -> Int) -> (b -> b -> Int) -> (a*b) -> (a*b) -> Int")), {i: compareProducts, 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: compareSums, t: mkType("(a -> a -> Int) -> (b -> b -> Int) -> (a+b) -> (a+b) -> Int")},
newDynamic(compareSets)(mkType("(a -> a -> Int) -> {a} -> {a} -> Int")), {i: compareSets, t: mkType("(a -> a -> Int) -> {a} -> {a} -> Int")},
newDynamic(compareDicts)(mkType("(a -> a -> Int) -> (b -> b-> Int) -> (a => b) -> (a => b) -> Int")) {i: compareDicts, t: mkType("(a -> a -> Int) -> (b -> b-> Int) -> (a => b) -> (a => b) -> Int")}
]; ];

View file

@ -1,9 +1,8 @@
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 = [
newDynamic(compareTypes)(mkType("Type -> Type -> Int")), {i: compareTypes, t: mkType("Type -> Type -> Int")},
]; ];

View file

@ -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...
// newDynamic(makeTypeConstructor)(mkType("UUID -> Int -> ??")) // {i: makeTypeConstructor, t: mkType("UUID -> Int -> ??")}
]; ];

View file

@ -7,7 +7,6 @@ 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.
@ -127,12 +126,12 @@ export const makeTypeParser = ({
} }
} }
const parseGroup = (expr, tokensInGroup, fn, labels, label) => { const parseGroup = (tokensInGroup, fn, labels, label) => {
// console.log('parseGroup ', tokensInGroup, fn); // console.log('parseGroup ', tokensInGroup, fn);
return (fn === null) return (fn === null)
? __parse(expr, tokensInGroup, labels, label) ? __parse(tokensInGroup, labels, label)
: fn(self => { : fn(self => {
return __parse(expr, tokensInGroup, extendLabels(labels, label, self)); return __parse(tokensInGroup, extendLabels(labels, label, self));
}); });
} }
@ -140,7 +139,7 @@ export const makeTypeParser = ({
return (label === null) ? labels : new Map([...labels, [label, self]]) return (label === null) ? labels : new Map([...labels, [label, self]])
}; };
const __parse = (expr, tokens, labels = new Map(), label = null) => { const __parse = (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])) {
@ -148,7 +147,7 @@ export const makeTypeParser = ({
} }
else { else {
// pass label and parse 'rest' // pass label and parse 'rest'
return __parse(expr, tokens.slice(1), labels, tokens[0]); return __parse(tokens.slice(1), labels, tokens[0]);
} }
} }
if (tokens.length === 1) { if (tokens.length === 1) {
@ -157,28 +156,26 @@ 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(expr, lhsTokens, fnGrp, labels, label); return parseGroup(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(expr, lhsTokens, fnGrp, extendLabels(labels, label, self)); return parseGroup(lhsTokens, fnGrp, extendLabels(labels, label, self));
})(self => { })(self => {
return __parse(expr, rhsTokens, extendLabels(labels, label, self)); return __parse(rhsTokens, extendLabels(labels, label, self));
}); });
} }
} }
throw new Error("unknown operator: "+operator+" in expression "+expr) throw new Error("unknown operator: "+operator)
} }
}; };
const parse = expr => { const parse = expr => {
const tokens = tokenize(expr); const tokens = tokenize(expr);
const parsed = __parse(expr, tokens); return __parse(tokens);
prettyT(parsed); // force evaluation
return parsed;
} }
return parse; return parse;

View file

@ -1,11 +1,10 @@
import { getDefaultTypeParser } from "../parser/type_parser.js"; import { getDefaultTypeParser } from "../parser/type_parser.js";
import { addDouble, eqDouble, mulDouble } from "./double.js"; import { addDouble, eqDouble, mulDouble } from "./double.js";
import { newDynamic } from "./dynamic.js";
const mkType = getDefaultTypeParser(); const mkType = getDefaultTypeParser();
export const ModuleDouble = [ export const ModuleDouble = [
newDynamic(addDouble)(mkType("Double -> Double -> Double")), { i: addDouble, t: mkType("Double -> Double -> Double") },
newDynamic(mulDouble)(mkType("Double -> Double -> Double") ), { i: mulDouble, t: mkType("Double -> Double -> Double") },
newDynamic(eqDouble)(mkType("Double -> Double -> Bool") ), { i: eqDouble, t: mkType("Double -> Double -> Bool") },
]; ];

View file

@ -1,14 +1,6 @@
import { inspect } from "node:util";
import { assignFn } from "../generics/generics.js"; import { assignFn } from "../generics/generics.js";
function inspectDynamic(_depth, options, inspect) { export const newDynamic = i => t => ({i, t});
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 getInst = lnk => lnk.i;
export const getType = lnk => lnk.t; export const getType = lnk => lnk.t;

View file

@ -4,13 +4,13 @@ import { apply, getInst, getType, newDynamic } from "./dynamic.js";
const mkType = getDefaultTypeParser(); const mkType = getDefaultTypeParser();
export const ModuleDynamic = [ export const ModuleDynamic = [
newDynamic(newDynamic)(mkType("a -> Type -> Dynamic")), { i: newDynamic, t: 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)
newDynamic(getInst)(mkType("Dynamic -> a") ), { i: getInst, t: mkType("Dynamic -> a") },
newDynamic(getType)(mkType("Dynamic -> Type") ), { i: getType, t: mkType("Dynamic -> Type") },
newDynamic(apply)(mkType("Dynamic -> Dynamic -> Dynamic") ), { i: apply, t: mkType("Dynamic -> Dynamic -> Dynamic") },
]; ];

View file

@ -1,11 +1,10 @@
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 = [
newDynamic(addInt)(mkType("Int -> Int -> Int") ), { i: addInt, t: mkType("Int -> Int -> Int") },
newDynamic(mulInt)(mkType("Int -> Int -> Int") ), { i: mulInt, t: mkType("Int -> Int -> Int") },
newDynamic(eqInt)(mkType("Int -> Int -> Bool") ), { i: eqInt, t: mkType("Int -> Int -> Bool") },
]; ];

View file

@ -1,30 +1,29 @@
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 = [
newDynamic(SymbolInt )(UUID ), { i: SymbolInt , t: UUID },
newDynamic(SymbolBool )(UUID ), { i: SymbolBool , t: UUID },
newDynamic(SymbolDouble )(UUID ), { i: SymbolDouble , t: UUID },
newDynamic(SymbolByte )(UUID ), { i: SymbolByte , t: UUID },
newDynamic(SymbolChar )(UUID ), { i: SymbolChar , t: UUID },
newDynamic(SymbolUnit )(UUID ), { i: SymbolUnit , t: UUID },
newDynamic(SymbolBottom )(UUID ), { i: SymbolBottom , t: UUID },
newDynamic(SymbolUUID )(UUID ), { i: SymbolUUID , t: UUID },
newDynamic(SymbolType )(UUID ), { i: SymbolType , t: UUID },
newDynamic(SymbolTop )(UUID ), { i: SymbolTop , t: UUID },
newDynamic(SymbolDynamic )(UUID ), { i: SymbolDynamic , t: UUID },
]; ];
export const ModulePrimitiveTypes = [ export const ModulePrimitiveTypes = [
newDynamic(Int )(Type ), { i: Int , t: Type },
newDynamic(Bool )(Type ), { i: Bool , t: Type },
newDynamic(Double )(Type ), { i: Double , t: Type },
newDynamic(Byte )(Type ), { i: Byte , t: Type },
newDynamic(Char )(Type ), { i: Char , t: Type },
newDynamic(Unit )(Type ), { i: Unit , t: Type },
newDynamic(Bottom )(Type ), { i: Bottom , t: Type },
newDynamic(UUID )(Type ), { i: UUID , t: Type },
newDynamic(Type )(Type ), { i: Type , t: Type },
newDynamic(Top )(Type ), { i: Top , t: Type },
newDynamic(Dynamic )(Type ), { i: Dynamic , t: Type },
]; ];

View file

@ -1,10 +1,9 @@
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 = [
newDynamic(getHumanReadableName)(mkType("UUID -> String")), { i: getHumanReadableName, t: mkType("UUID -> String")},
newDynamic(eqSymbol)(mkType("UUID -> UUID -> Bool")), { i: eqSymbol, t: mkType("UUID -> UUID -> Bool")},
]; ];

View file

@ -1,14 +1,13 @@
// 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 = [
newDynamic(eqType )(mkType("Type -> Type -> Bool")), {i: eqType , t: mkType("Type -> Type -> Bool")},
newDynamic(getSymbol)(mkType("Type -> UUID")), {i: getSymbol, t: mkType("Type -> UUID")},
newDynamic(getParams)(mkType("Type -> [Type -> Type]")), {i: getParams, t: mkType("Type -> [Type -> Type]")},
]; ];

View file

@ -1,10 +1,9 @@
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 = [
newDynamic(unit )(mkType("Unit")), {i: unit , t: mkType("Unit")},
newDynamic(eqUnit)(mkType("Unit -> Unit -> Bool")), {i: eqUnit, t: mkType("Unit -> Unit -> Bool")},
]; ];

View file

@ -1,7 +1,6 @@
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';
@ -13,12 +12,12 @@ const mkType = makeTypeParser({
}); });
export const ModuleDict = [ export const ModuleDict = [
newDynamic(emptyDict )(mkType("(a -> a -> Int) -> (a => b)") ), { i: emptyDict , t: mkType("(a -> a -> Int) -> (a => b)") },
newDynamic(has )(mkType("(a => b) -> a -> Bool")), { i: has , t: mkType("(a => b) -> a -> Bool")},
newDynamic(set )(mkType("(a => b) -> a -> b -> (a => b)")), { i: set , t: mkType("(a => b) -> a -> b -> (a => b)")},
newDynamic(remove )(mkType("(a => b) -> a -> (a => b)")), { i: remove , t: mkType("(a => b) -> a -> (a => b)")},
newDynamic(length )(mkType("(a => b) -> Int")), { i: length , t: mkType("(a => b) -> Int")},
newDynamic(first )(mkType("(a => b) -> (a |=>| b)")), { i: first , t: mkType("(a => b) -> (a |=>| b)")},
newDynamic(last )(mkType("(a => b) -> (a |=>| b)")), { i: last , t: mkType("(a => b) -> (a |=>| b)")},
newDynamic(read )(mkType("(a |=>| b) -> (Unit + ((a*b) * (a |=>| b)))")), { i: read , t: mkType("(a |=>| b) -> (Unit + ((a*b) * (a |=>| b)))")},
]; ];

View file

@ -1,16 +1,15 @@
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 = [
newDynamic(emptyList)(mkType("[a]")), { i: emptyList, t: mkType("[a]")},
newDynamic(get )(mkType("[a] -> Int -> a")), { i: get , t: mkType("[a] -> Int -> a")},
newDynamic(put )(mkType("[a] -> Int -> a -> [a]")), { i: put , t: mkType("[a] -> Int -> a -> [a]")},
newDynamic(push )(mkType("[a] -> a -> [a]")), { i: push , t: mkType("[a] -> a -> [a]")},
newDynamic(pop )(mkType("[a] -> a")), { i: pop , t: mkType("[a] -> a")},
newDynamic(map )(mkType("[a] -> (a -> b) -> [b]")), { i: map , t: mkType("[a] -> (a -> b) -> [b]")},
newDynamic(length )(mkType("[a] -> Int")), { i: length , t: mkType("[a] -> Int")},
newDynamic(fold )(mkType("[a] -> (b -> a -> b) -> b -> b")), { i: fold , t: mkType("[a] -> (b -> a -> b) -> b -> b")},
]; ];

View file

@ -1,11 +1,10 @@
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 = [
newDynamic(newProduct)(mkType("a -> b -> (a * b)") ), { i: newProduct, t: mkType("a -> b -> (a * b)") },
newDynamic(getLeft )(mkType("(a * b) -> a" ) ), { i: getLeft , t: mkType("(a * b) -> a" ) },
newDynamic(getRight )(mkType("(a * b) -> b" ) ), { i: getRight , t: mkType("(a * b) -> b" ) },
]; ];

View file

@ -1,7 +1,6 @@
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';
@ -12,13 +11,13 @@ const mkType = makeTypeParser({
}); });
export const ModuleSet = [ export const ModuleSet = [
newDynamic(emptySet )(mkType("(a -> a -> Int) -> {a}") ), { i: emptySet , t: mkType("(a -> a -> Int) -> {a}") },
newDynamic(has )(mkType("{a} -> a -> Bool")), { i: has , t: mkType("{a} -> a -> Bool")},
newDynamic(add )(mkType("{a} -> a -> {a}")), { i: add , t: mkType("{a} -> a -> {a}")},
newDynamic(remove )(mkType("{a} -> a -> {a}")), { i: remove , t: mkType("{a} -> a -> {a}")},
newDynamic(length )(mkType("{a} -> Int")), { i: length , t: mkType("{a} -> Int")},
newDynamic(fold )(mkType("{a} -> (b -> a -> b) -> b")), { i: fold , t: mkType("{a} -> (b -> a -> b) -> b")},
newDynamic(first )(mkType("{a} -> <a>")), { i: first , t: mkType("{a} -> <a>")},
newDynamic(last )(mkType("{a} -> <a>")), { i: last , t: mkType("{a} -> <a>")},
newDynamic(read )(mkType("<a> -> (Unit + (a * <a>))")), { i: read , t: mkType("<a> -> (Unit + (a * <a>))")},
]; ];

View file

@ -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 = [
// newDynamic(type)(Type), // {i: type, t: Type},
// constructor // constructor
newDynamic(ctor)(ctorType), {i: ctor, t: 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 = [
newDynamic(structType)(mkType("[String*Type] -> Type")), {i: structType, t: mkType("[String*Type] -> Type")},
newDynamic(makeModuleStruct)(mkType("[String*Type] -> [Dynamic]")), {i: makeModuleStruct, t: mkType("[String*Type] -> [Dynamic]")},
]; ];

View file

@ -1,11 +1,10 @@
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 = [
newDynamic(newLeft )(mkType("a -> (a + b)") ), { i: newLeft , t: mkType("a -> (a + b)") },
newDynamic(newRight )(mkType("b -> (a + b)") ), { i: newRight , t: mkType("b -> (a + b)") },
newDynamic(match )(mkType("(a + b) -> (a -> c) -> (b -> c) -> c") ), { i: match , t: mkType("(a + b) -> (a -> c) -> (b -> c) -> c") },
]; ];

View file

@ -1,5 +1,4 @@
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";
@ -11,12 +10,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 = [
newDynamic(symbolSet )(UUID ), { i: symbolSet , t: UUID },
newDynamic(symbolList )(UUID ), { i: symbolList , t: UUID },
newDynamic(symbolProduct )(UUID ), { i: symbolProduct , t: UUID },
newDynamic(symbolSum )(UUID ), { i: symbolSum , t: UUID },
newDynamic(symbolDict )(UUID ), { i: symbolDict , t: UUID },
newDynamic(symbolFunction )(UUID ), { i: symbolFunction , t: UUID },
]; ];
const unaryTypeConstructor = fnType(_ => Type)(_ => Type); const unaryTypeConstructor = fnType(_ => Type)(_ => Type);
@ -24,10 +23,10 @@ const unaryTypeConstructor = fnType(_ => Type)(_ => Type);
const binaryTypeConstructor = fnType(_ => Type)(_ => unaryTypeConstructor); const binaryTypeConstructor = fnType(_ => Type)(_ => unaryTypeConstructor);
export const ModuleTypeConstructors = [ export const ModuleTypeConstructors = [
newDynamic(setType )(unaryTypeConstructor ), { i: setType , t: unaryTypeConstructor },
newDynamic(lsType )(unaryTypeConstructor ), { i: lsType , t: unaryTypeConstructor },
newDynamic(prodType )(binaryTypeConstructor ), { i: prodType , t: binaryTypeConstructor },
newDynamic(sumType )(binaryTypeConstructor ), { i: sumType , t: binaryTypeConstructor },
newDynamic(dictType )(binaryTypeConstructor ), { i: dictType , t: binaryTypeConstructor },
newDynamic(fnType )(binaryTypeConstructor ), { i: fnType , t: binaryTypeConstructor },
]; ];