much improved type inferencing

This commit is contained in:
Joeri Exelmans 2025-05-19 15:01:30 +02:00
parent 28e5032923
commit d877b42a12
5 changed files with 150 additions and 103 deletions

View file

@ -1,13 +1,20 @@
import { createContext } from "react";
import { getDefaultTypeParser, module2Env, ModuleStd } from "dope2";
import type { Dynamic, Environment } from "./eval";
export const functionWith3Params = i => j => k => i+j+k;
export const functionWith4Params = i => j => k => l => i+j+k+l;
const mkType = getDefaultTypeParser();
export const extendedEnv = module2Env(ModuleStd.concat([
["functionWith3Params", { i: functionWith3Params, t: mkType("Int->Int->Int->Int") }],
["functionWith4Params", { i: functionWith4Params, t: mkType("Int->Int->Int->Int->Int")}]
]));
export const extendedEnv: Environment = {
names: module2Env(ModuleStd.concat([
["functionWith3Params", { i: functionWith3Params, t: mkType("Int->Int->Int->Int") }],
["functionWith4Params", { i: functionWith4Params, t: mkType("Int->Int->Int->Int->Int")}]
]).map(([name, {i,t}]) => [name, { kind: "value", i, t, unification: new Map() }] as [string, Dynamic])
).name2dyn,
nextFreeTypeVar: 0,
typeVars: new Set(),
};
export const EnvContext = createContext(extendedEnv);