turn the function for creating new types (or type constructors) into a DOPE function

This commit is contained in:
Joeri Exelmans 2025-03-31 17:35:30 +02:00
parent d8ca2f3999
commit a0e3aa0cb3
12 changed files with 112 additions and 58 deletions

View file

@ -2,8 +2,6 @@ import { Type } from "../primitives/types.js";
import { typedFnType } from "./types.js";
import { fnType } from "./types.js";
// export const pprintFn = fnT => ``
export const ModuleFunction = {l:[
// binary type constructor: Type -> Type -> Type
...typedFnType(fnType, fnType => fnType

View file

@ -4,7 +4,7 @@ import { sumType, prodType, fnType } from "./types.js";
export const createNominalADT = symbol => variants => {
makeTypeConstructor(symbol, 0, )
};
export const createNominalADTFnType =

View file

@ -9,7 +9,7 @@ import { getSymbol, makeTypeConstructor } from "../type_constructor.js";
// It is a cheap workaround for JS lacking customizable hash-functions and equality-testing-functions.
// This same pattern is repeated throughout the code for all non-nullary type constructors (list, sum, product, ...)
const symbolFunction = Symbol('Function');
export const fnType = makeTypeConstructor(symbolFunction, 2);
export const fnType = makeTypeConstructor(symbolFunction)(2);
export const isFunction = type => getSymbol(type) === symbolFunction;
@ -40,25 +40,26 @@ export const typedFnType2 = callback => {
// Sum type
const symbolSum = Symbol("Sum");
export const sumType = makeTypeConstructor(symbolSum, 2);
export const sumType = makeTypeConstructor(symbolSum)(2);
// Product type
const symbolProduct = Symbol("Product");
export const prodType = makeTypeConstructor(symbolProduct, 2);
export const prodType = makeTypeConstructor(symbolProduct)(2);
// List type
const symbolList = Symbol('List');
export const lsType = makeTypeConstructor(symbolList, 1);
export const lsType = makeTypeConstructor(symbolList)(1);
// Set type
const symbolSet = Symbol('Set');
export const setType = makeTypeConstructor(symbolSet, 1);
export const setType = makeTypeConstructor(symbolSet)(1);
// Pretty print type
export function prettyT(type) {
// console.log("pretty:", type);
if (type.typeVars) {
if (type.typeVars.size > 0) {
return `${[...type.typeVars].map(prettyT).join(", ")}: ${prettyT(type.type)}`;

View file

@ -6,7 +6,7 @@ import { eqDictType } from "../typeclasses/eq_type.js";
import { fnType, setType } from "./types.js";
const symbolVersioned = Symbol("Versioned");
export const versionedType = makeTypeConstructor(symbolVersioned, 1);
export const versionedType = makeTypeConstructor(symbolVersioned)(1);
export const constructor = parents => value => {