fix some things
This commit is contained in:
parent
d9111c3969
commit
bbac7858ae
16 changed files with 69 additions and 55 deletions
|
|
@ -4,7 +4,7 @@ import { DefaultMap } from "../lib/util/defaultmap.js";
|
|||
import { pretty } from '../lib/util/pretty.js';
|
||||
import { isFunction } from '../structures/types.js';
|
||||
import { ModuleStd } from '../lib/stdlib.js';
|
||||
import { Double, GenericType, Int, SymbolT, Type } from "../primitives/types.js";
|
||||
import { Double, GenericType, Int, UUID, Type } from "../primitives/types.js";
|
||||
import { eqType } from '../primitives/type.js';
|
||||
import { Top } from "../primitives/types.js";
|
||||
import { assignFn, makeGeneric, onlyOccurring } from '../lib/generics/generics.js';
|
||||
|
|
@ -287,7 +287,7 @@ async function createInstance(t) {
|
|||
});
|
||||
return n;
|
||||
}
|
||||
else if (eqType(t)(SymbolT)) {
|
||||
else if (eqType(t)(UUID)) {
|
||||
console.log("Note: you are creating a new Symbol. Even if the description matches that of another symbol (e.g., \"Int\"), a new Symbol will be created that is unique and only equal to itself.");
|
||||
const symbolDescr = await input({message: "enter symbol description:"});
|
||||
return symbolDescr + '__' + genUUID(16);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,6 @@ import { compareDynamic, makeCompareFn } from "./dynamic.js";
|
|||
const mkType = getDefaultTypeParser();
|
||||
|
||||
export const ModuleCompareDynamic = [
|
||||
{i: makeCompareFn , t: mkType("∀a: Type -> a -> a -> Int")},
|
||||
{i: makeCompareFn , t: mkType("Type -> a -> a -> Int")},
|
||||
{i: compareDynamic, t: mkType("Dynamic -> Dynamic -> Int")},
|
||||
];
|
||||
|
|
@ -7,5 +7,5 @@ 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("SymbolT -> SymbolT -> Int")},
|
||||
{i: compareSymbols, t: mkType("UUID -> UUID -> Int")},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ import { compareDicts, compareLists, compareProducts, compareSets, compareSums }
|
|||
const mkType = getDefaultTypeParser();
|
||||
|
||||
export const ModuleCompareStructures = [
|
||||
{i: compareLists, t: mkType("∀a: (a -> a -> Int) -> [a] -> [a] -> Int")},
|
||||
{i: compareLists, t: mkType("(a -> a -> Int) -> [a] -> [a] -> Int")},
|
||||
|
||||
{i: compareProducts, t: mkType("∀a,b: (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")},
|
||||
|
||||
{i: compareSums, t: mkType("∀a,b: (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")},
|
||||
|
||||
{i: compareSets, t: mkType("∀a: (a -> a -> Int) -> {a} -> {a} -> Int")},
|
||||
{i: compareSets, t: mkType("(a -> a -> Int) -> {a} -> {a} -> Int")},
|
||||
|
||||
{i: compareDicts, t: mkType("∀a,b: (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")}
|
||||
];
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { isTypeVar, TYPE_VARS } from "../primitives/typevars.js";
|
|||
|
||||
// helper for creating generic types
|
||||
// for instance, the type:
|
||||
// ∀a: a -> a -> Bool
|
||||
// a -> a -> Bool
|
||||
// is created by
|
||||
// makeGeneric(a => fnType(() => a)(() => fnType(() => a)(() => Bool)))
|
||||
export const makeGeneric = callback => {
|
||||
|
|
|
|||
|
|
@ -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("SymbolT -> Int -> ??")}
|
||||
// {i: makeTypeConstructor, t: mkType("UUID -> Int -> ??")}
|
||||
];
|
||||
|
|
|
|||
|
|
@ -8,6 +8,11 @@ import { TYPE_VARS } from "../primitives/typevars.js";
|
|||
import { dictType, fnType, lsType, prodType, sumType } from "../structures/type_constructors.js";
|
||||
import { setType } from "../structures/type_constructors.js";
|
||||
|
||||
// A very stupid little parser, that can only parse:
|
||||
// - primitives => simply maps onto types.
|
||||
// - things between brackets => calls a type constructor that takes one parameter on whatever is between the brackets.
|
||||
// - binary (infix) operators => calls a type constructor that takes two parameters on the LHS and RHS.
|
||||
|
||||
export const makeTypeParser = ({
|
||||
// parser can be extended:
|
||||
extraPrimitives=[],
|
||||
|
|
@ -49,13 +54,6 @@ export const makeTypeParser = ({
|
|||
['⇒', dictType],
|
||||
['=>', dictType],
|
||||
|
||||
// only used for type variables (e.g., ∀a,b,c:)
|
||||
[',', fnX => fnY => {
|
||||
const x = fnX();
|
||||
const y = fnY();
|
||||
return Array.isArray(x) ? x.concat(y) : [x].concat(y)
|
||||
}],
|
||||
|
||||
...extraInfixOperators,
|
||||
]);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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") },
|
||||
];
|
||||
|
|
|
|||
|
|
@ -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")},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -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]")},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ const mkType = makeTypeParser({
|
|||
});
|
||||
|
||||
export const ModuleDict = [
|
||||
{ i: emptyDict , t: mkType("∀a,b: (a -> a -> Int) -> (a => b)") },
|
||||
{ i: has , t: mkType("∀a,b: (a => b) -> a -> Bool")},
|
||||
{ i: set , t: mkType("∀a,b: (a => b) -> a -> b -> (a => b)")},
|
||||
{ i: remove , t: mkType("∀a,b: (a => b) -> a -> (a => b)")},
|
||||
{ i: length , t: mkType("∀a,b: (a => b) -> Int")},
|
||||
{ i: first , t: mkType("∀a,b: (a => b) -> (a |=>| b)")},
|
||||
{ i: last , t: mkType("∀a,b: (a => b) -> (a |=>| b)")},
|
||||
{ i: read , t: mkType("∀a,b: (a |=>| b) -> (Unit + ((a*b) * (a |=>| b)))")},
|
||||
{ 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)))")},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ import { emptyList, fold, get, length, map, pop, push, put } from "./list.js";
|
|||
const mkType = getDefaultTypeParser();
|
||||
|
||||
export const ModuleList = [
|
||||
{ i: emptyList, t: mkType("∀a: [a]")},
|
||||
{ i: get , t: mkType("∀a: [a] -> Int -> a")},
|
||||
{ i: put , t: mkType("∀a: [a] -> Int -> a -> [a]")},
|
||||
{ i: push , t: mkType("∀a: [a] -> a -> [a]")},
|
||||
{ i: pop , t: mkType("∀a: [a] -> a")},
|
||||
{ i: map , t: mkType("∀a: [a] -> (a -> b) -> [b]")},
|
||||
{ i: length , t: mkType("∀a: [a] -> Int")},
|
||||
{ i: fold , t: mkType("∀a: [a] -> (b -> a -> b) -> b -> b")},
|
||||
{ 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")},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { newProduct, getLeft, getRight } from "./product.js";
|
|||
const mkType = getDefaultTypeParser();
|
||||
|
||||
export const ModuleProduct = [
|
||||
{ i: newProduct, t: mkType("∀a,b: a -> b -> (a * b)") },
|
||||
{ i: getLeft , t: mkType("∀a,b: (a * b) -> a" ) },
|
||||
{ i: getRight , t: mkType("∀a,b: (a * b) -> b" ) },
|
||||
{ i: newProduct, t: mkType("a -> b -> (a * b)") },
|
||||
{ i: getLeft , t: mkType("(a * b) -> a" ) },
|
||||
{ i: getRight , t: mkType("(a * b) -> b" ) },
|
||||
];
|
||||
|
|
|
|||
|
|
@ -9,13 +9,13 @@ const mkType = makeTypeParser({
|
|||
});
|
||||
|
||||
export const ModuleSet = [
|
||||
{ i: emptySet , t: mkType("∀a: (a -> a -> Int) -> {a}") },
|
||||
{ i: has , t: mkType("∀a: {a} -> a -> Bool")},
|
||||
{ i: add , t: mkType("∀a: {a} -> a -> {a}")},
|
||||
{ i: remove , t: mkType("∀a: {a} -> a -> {a}")},
|
||||
{ i: length , t: mkType("∀a: {a} -> Int")},
|
||||
{ i: fold , t: mkType("∀a,b: {a} -> (b -> a -> b) -> b")},
|
||||
{ i: first , t: mkType("∀a: {a} -> <a>")},
|
||||
{ i: last , t: mkType("∀a: {a} -> <a>")},
|
||||
{ i: read , t: mkType("∀a: <a> -> (Unit + (a * <a>))")},
|
||||
{ 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>))")},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { match, newLeft, newRight } from "./sum.js";
|
|||
const mkType = getDefaultTypeParser();
|
||||
|
||||
export const ModuleSum = [
|
||||
{ i: newLeft , t: mkType("∀a,b: a -> (a + b)") },
|
||||
{ i: newRight , t: mkType("∀a,b: b -> (a + b)") },
|
||||
{ i: match , t: mkType("∀a,b,c: (a + b) -> (a -> c) -> (b -> c) -> c") },
|
||||
{ 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") },
|
||||
];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue