fix some things

This commit is contained in:
Joeri Exelmans 2025-05-08 21:30:56 +02:00
parent d9111c3969
commit bbac7858ae
16 changed files with 69 additions and 55 deletions

View file

@ -1,3 +1,17 @@
import { assignFn } from "../generics/generics.js";
export const newDynamic = i => t => ({i, t});
export const getInst = lnk => lnk.i;
export const getType = lnk => lnk.t;
export const apply = input => fun => {
const inputType = getType(input)
const funType = getType(fun);
const outputType = assignFn(funType, inputType);
const inputValue = getInst(input);
const funValue = getInst(fun);
const outputValue = funValue(inputValue);
return newDynamic(outputValue, outputType);
};

View file

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

View file

@ -4,6 +4,6 @@ import { eqSymbol, getHumanReadableName } from "./symbol.js";
const mkType = getDefaultTypeParser();
export const ModuleSymbol = [
{ i: getHumanReadableName, t: mkType("SymbolT -> String")},
{ i: eqSymbol, t: mkType("SymbolT -> SymbolT -> Bool")},
{ i: getHumanReadableName, t: mkType("UUID -> String")},
{ i: eqSymbol, t: mkType("UUID -> UUID -> Bool")},
];

View file

@ -8,6 +8,6 @@ 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 -> SymbolT")},
{i: getSymbol, t: mkType("Type -> UUID")},
{i: getParams, t: mkType("Type -> [Type -> Type]")},
];