(broken) modules are mappings from name to typed value
This commit is contained in:
parent
c27c7d3648
commit
639d70afa5
21 changed files with 125 additions and 132 deletions
|
|
@ -13,13 +13,13 @@ const mkType = makeTypeParser({
|
|||
});
|
||||
|
||||
export const ModuleDict = [
|
||||
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(fold )(mkType("(c -> a -> b -> c) -> c -> (a => b) -> c ")),
|
||||
newDynamic(first )(mkType("(a => b) -> (a |=>| b) ")),
|
||||
newDynamic(last )(mkType("(a => b) -> (a |=>| b) ")),
|
||||
newDynamic(read )(mkType("(a |=>| b) -> (Unit + ((a*b) * (a |=>| b)))")),
|
||||
["emptyDict", newDynamic(emptyDict)(mkType("(a -> a -> Int) -> (a => b) "))],
|
||||
["has" , newDynamic(has )(mkType("(a => b) -> a -> Bool "))],
|
||||
["set" , newDynamic(set )(mkType("(a => b) -> a -> b -> (a => b) "))],
|
||||
["remove" , newDynamic(remove )(mkType("(a => b) -> a -> (a => b) "))],
|
||||
["length" , newDynamic(length )(mkType("(a => b) -> Int "))],
|
||||
["fold" , newDynamic(fold )(mkType("(c -> a -> b -> c) -> c -> (a => b) -> c "))],
|
||||
["first" , newDynamic(first )(mkType("(a => b) -> (a |=>| b) "))],
|
||||
["last" , newDynamic(last )(mkType("(a => b) -> (a |=>| b) "))],
|
||||
["read" , newDynamic(read )(mkType("(a |=>| b) -> (Unit + ((a*b) * (a |=>| b)))"))],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -65,11 +65,11 @@ export const makeModuleEnum = type => variants => {
|
|||
const matchFn = makeMatchFn(variants);
|
||||
const matchFnType = makeMatchFnType(type)(variants);
|
||||
const module = [
|
||||
// newDynamic(type)(Type),
|
||||
// ["type", newDynamic(type)(Type)],
|
||||
|
||||
// constructors:
|
||||
...zip(ctors, ctorTypes)
|
||||
.map(([ctor, ctorType]) => newDynamic(ctor)(ctorType)),
|
||||
.map(([ctor, ctorType]) => ["ctor", newDynamic(ctor)(ctorType)]),
|
||||
|
||||
// match-function:
|
||||
newDynamic(matchFn, matchFnType),
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ import { emptyList, fold, get, length, map, pop, push, put } from "./list.js";
|
|||
const mkType = getDefaultTypeParser();
|
||||
|
||||
export const ModuleList = [
|
||||
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("(b -> a -> b) -> b -> [a] -> b")),
|
||||
["emptyList", newDynamic(emptyList)(mkType("[a]" ))],
|
||||
["get" , newDynamic(get )(mkType("[a] -> Int -> a" ))],
|
||||
["put" , newDynamic(put )(mkType("[a] -> Int -> a -> [a]" ))],
|
||||
["push" , newDynamic(push )(mkType("[a] -> a -> [a]" ))],
|
||||
["pop" , newDynamic(pop )(mkType("[a] -> a" ))],
|
||||
["map" , newDynamic(map )(mkType("[a] -> (a -> b) -> [b]" ))],
|
||||
["length" , newDynamic(length )(mkType("[a] -> Int" ))],
|
||||
["fold" , newDynamic(fold )(mkType("(b -> a -> b) -> b -> [a] -> b"))],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { newProduct, getLeft, getRight } from "./product.js";
|
|||
const mkType = getDefaultTypeParser();
|
||||
|
||||
export const ModuleProduct = [
|
||||
newDynamic(newProduct)(mkType("a -> b -> (a * b)") ),
|
||||
newDynamic(getLeft )(mkType("(a * b) -> a" ) ),
|
||||
newDynamic(getRight )(mkType("(a * b) -> b" ) ),
|
||||
["newProduct", newDynamic(newProduct)(mkType("a -> b -> (a * b)"))],
|
||||
["getLeft" , newDynamic(getLeft )(mkType("(a * b) -> a" ))],
|
||||
["getRight" , newDynamic(getRight )(mkType("(a * b) -> b" ))],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -13,13 +13,13 @@ const mkType = makeTypeParser({
|
|||
});
|
||||
|
||||
export const ModuleSet = [
|
||||
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("(b -> a -> b) -> b -> {a} -> b")),
|
||||
newDynamic(first )(mkType("{a} -> <a>" )),
|
||||
newDynamic(last )(mkType("{a} -> <a>" )),
|
||||
newDynamic(read )(mkType("<a> -> (Unit + (a * <a>))" )),
|
||||
["emptySet", newDynamic(emptySet)(mkType("(a -> a -> Int) -> {a}" ))],
|
||||
["has" , newDynamic(has )(mkType("{a} -> a -> Bool" ))],
|
||||
["add" , newDynamic(add )(mkType("{a} -> a -> {a}" ))],
|
||||
["remove" , newDynamic(remove )(mkType("{a} -> a -> {a}" ))],
|
||||
["length" , newDynamic(length )(mkType("{a} -> Int" ))],
|
||||
["fold" , newDynamic(fold )(mkType("(b -> a -> b) -> b -> {a} -> b"))],
|
||||
["first" , newDynamic(first )(mkType("{a} -> <a>" ))],
|
||||
["last" , newDynamic(last )(mkType("{a} -> <a>" ))],
|
||||
["read" , newDynamic(read )(mkType("<a> -> (Unit + (a * <a>))" ))],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -57,14 +57,14 @@ export const makeModuleStruct = type => fields => {
|
|||
const getterTypes = makeGettersTypes(fields);
|
||||
const getters = makeGetters(fieldNames);
|
||||
const module = [
|
||||
// newDynamic(type)(Type),
|
||||
// ["type", newDynamic(type)(Type)],
|
||||
|
||||
// constructor
|
||||
newDynamic(ctor)(ctorType),
|
||||
["ctor", newDynamic(ctor)(ctorType)],
|
||||
|
||||
// getters:
|
||||
...zip(getters, getterTypes)
|
||||
.map(([getter, getterType]) => newDynamic(getter)(getterType)),
|
||||
.map(([getter, getterType]) => ["getter", newDynamic(getter)(getterType)]),
|
||||
];
|
||||
return module;
|
||||
};
|
||||
|
|
@ -72,6 +72,6 @@ export const makeModuleStruct = type => fields => {
|
|||
const mkType = getDefaultTypeParser();
|
||||
|
||||
export const ModuleStruct = [
|
||||
newDynamic(structType)(mkType("[String*Type] -> Type")),
|
||||
newDynamic(makeModuleStruct)(mkType("[String*Type] -> [Dynamic]")),
|
||||
["structType" , newDynamic(structType )(mkType("[String*Type] -> Type" ))],
|
||||
["makeModuleStruct", newDynamic(makeModuleStruct)(mkType("[String*Type] -> [Dynamic]"))],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { match, newLeft, newRight } from "./sum.js";
|
|||
const mkType = getDefaultTypeParser();
|
||||
|
||||
export const ModuleSum = [
|
||||
newDynamic(newLeft )(mkType("a -> (a + b)") ),
|
||||
newDynamic(newRight )(mkType("b -> (a + b)") ),
|
||||
newDynamic(match )(mkType("(a + b) -> (a -> c) -> (b -> c) -> c") ),
|
||||
["newLeft" , newDynamic(newLeft )(mkType("a -> (a + b)" ))],
|
||||
["newRight" , newDynamic(newRight )(mkType("b -> (a + b)" ))],
|
||||
["match" , newDynamic(match )(mkType("(a + b) -> (a -> c) -> (b -> c) -> c"))],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@ export const setType = makeTypeConstructor(symbolSet)(1);
|
|||
export const dictType = makeTypeConstructor(symbolDict)(2);
|
||||
|
||||
export const ModuleStructuralSymbols = [
|
||||
newDynamic(symbolSet )(UUID),
|
||||
newDynamic(symbolList )(UUID),
|
||||
newDynamic(symbolProduct )(UUID),
|
||||
newDynamic(symbolSum )(UUID),
|
||||
newDynamic(symbolDict )(UUID),
|
||||
newDynamic(symbolFunction)(UUID),
|
||||
["symbolSet" , newDynamic(symbolSet )(UUID)],
|
||||
["symbolList" , newDynamic(symbolList )(UUID)],
|
||||
["symbolProduct" , newDynamic(symbolProduct )(UUID)],
|
||||
["symbolSum" , newDynamic(symbolSum )(UUID)],
|
||||
["symbolDict" , newDynamic(symbolDict )(UUID)],
|
||||
["symbolFunction", newDynamic(symbolFunction)(UUID)],
|
||||
];
|
||||
|
||||
const unaryTypeConstructor = fnType
|
||||
|
|
@ -28,10 +28,10 @@ const binaryTypeConstructor = fnType
|
|||
(_ => unaryTypeConstructor);
|
||||
|
||||
export const ModuleTypeConstructors = [
|
||||
newDynamic(setType )(unaryTypeConstructor ),
|
||||
newDynamic(lsType )(unaryTypeConstructor ),
|
||||
newDynamic(prodType)(binaryTypeConstructor),
|
||||
newDynamic(sumType )(binaryTypeConstructor),
|
||||
newDynamic(dictType)(binaryTypeConstructor),
|
||||
newDynamic(fnType )(binaryTypeConstructor),
|
||||
["setType" , newDynamic(setType )(unaryTypeConstructor )],
|
||||
["lsType" , newDynamic(lsType )(unaryTypeConstructor )],
|
||||
["prodType", newDynamic(prodType)(binaryTypeConstructor)],
|
||||
["sumType" , newDynamic(sumType )(binaryTypeConstructor)],
|
||||
["dictType", newDynamic(dictType)(binaryTypeConstructor)],
|
||||
["fnType" , newDynamic(fnType )(binaryTypeConstructor)],
|
||||
];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue