use newDynamic() everywhere instead of { i: ... , t: ... }

This commit is contained in:
Joeri Exelmans 2025-05-08 23:56:58 +02:00
parent 34d06aa82a
commit e1a2139cb4
22 changed files with 141 additions and 124 deletions

View file

@ -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)))")),
];

View file

@ -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")),
];

View file

@ -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" ) ),
];

View file

@ -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} -> <a>")},
{ i: last , t: mkType("{a} -> <a>")},
{ i: read , t: mkType("<a> -> (Unit + (a * <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} -> <a>")),
newDynamic(last )(mkType("{a} -> <a>")),
newDynamic(read )(mkType("<a> -> (Unit + (a * <a>))")),
];

View file

@ -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]")),
];

View file

@ -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") ),
];

View file

@ -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 ),
];