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,13 +1,14 @@
import { setType, typedFnType } from "./types.js";
import { Bool, Type } from "../primitives/types.js";
import { Bool, GenericType, Type } from "../primitives/types.js";
import { makeGeneric } from "../generics/generics.js";
// 'normal' implementation
const emptySet = new Set();
const emptySetType = makeGeneric(a => setType(a));
const has = set => elem => set.has(elem);
const add = set => elem => new Set([...set, elem]);
export const ModuleList = {l:[
export const ModuleSet = {l:[
// Type -> Type
...typedFnType(setType, fnType =>
fnType
@ -15,7 +16,8 @@ export const ModuleList = {l:[
/* out */ (Type)
),
{i: emptySet, t: makeGeneric(a => setType(a))},
{i: emptySet , t: emptySetType},
{i: emptySetType, t: GenericType },
...typedFnType(has, fnType =>
makeGeneric(a =>
@ -24,7 +26,7 @@ export const ModuleList = {l:[
/* out */ (fnType
/* in */ (a)
/* out */ (Bool)
))),
)), GenericType),
...typedFnType(add, fnType =>
makeGeneric(a =>
@ -33,6 +35,5 @@ export const ModuleList = {l:[
/* out */ (fnType
/* in */ (a)
/* out */ (setType(a))
))),
)), GenericType),
]};