39 lines
1,009 B
JavaScript
39 lines
1,009 B
JavaScript
import { setType, typedFnType } from "./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 ModuleSet = {l:[
|
|
// Type -> Type
|
|
...typedFnType(setType, fnType =>
|
|
fnType
|
|
/* in */ (Type)
|
|
/* out */ (Type)
|
|
),
|
|
|
|
{i: emptySet , t: emptySetType},
|
|
{i: emptySetType, t: GenericType },
|
|
|
|
...typedFnType(has, fnType =>
|
|
makeGeneric(a =>
|
|
fnType
|
|
/* in */ (setType(a))
|
|
/* out */ (fnType
|
|
/* in */ (a)
|
|
/* out */ (Bool)
|
|
)), GenericType),
|
|
|
|
...typedFnType(add, fnType =>
|
|
makeGeneric(a =>
|
|
fnType
|
|
/* in */ (setType(a))
|
|
/* out */ (fnType
|
|
/* in */ (a)
|
|
/* out */ (setType(a))
|
|
)), GenericType),
|
|
]};
|