interactive prompt can handle polymorphic types

This commit is contained in:
Joeri Exelmans 2025-04-02 15:49:43 +02:00
parent a0e3aa0cb3
commit 4a4983f693
20 changed files with 485 additions and 276 deletions

View file

@ -1,18 +1,22 @@
import { typedFnType } from "./structures/types.js";
import { Type } from "./primitives/types.js";
import { makeTypeConstructor } from "./type_constructor.js";
// Everything is (implicitly) typed by the Any type.
export const Any = { symbol: Symbol('Any'), params: [] };
const symbolAny = Symbol('Any');
export const Any = makeTypeConstructor(symbolAny)(0);
// A type-link, connecting a value to its Type.
export const Typed = { symbol: Symbol('Typed'), params: [] };
const symbolTyped = Symbol('Typed');
export const Typed = makeTypeConstructor(symbolTyped)(0);
const getInst = lnk => lnk.i;
const getType = lnk => lnk.t;
export const ModuleTyped = {l:[
{i: Typed, t: Type},
{i: Any , t: Type},
...typedFnType(getInst, fnType => fnType(Typed)(Type)),
...typedFnType(getType, fnType => fnType(Typed)(Type)),
...typedFnType(getInst, fnType => fnType(Typed)(Any)),
...typedFnType(getType, fnType => fnType(Typed)(Any)),
]};