This commit is contained in:
Joeri Exelmans 2025-03-24 17:28:07 +01:00
parent 6af72e525c
commit 145835ad5d
22 changed files with 153 additions and 90 deletions

13
util.js
View file

@ -1,3 +1,6 @@
import { inspect } from 'node:util';
import { symbolFunction, symbolList, symbolProduct, symbolSum } from './structures/types.js';
// re-inventing the wheel:
export function deepEqual(a, b) {
if (a === b) return true; // <- shallow equality and primitives
@ -45,17 +48,17 @@ export class DefaultMap {
}
}
import { inspect } from 'node:util';
import { symbolFunction, symbolList, symbolProduct, symbolSum } from './structures/types.js';
export function pretty(obj) {
return inspect(obj, {colors: true, depth: null});
}
// Pretty print type
export function prettyT(type) {
if (type.typeVars) {
return `${[...type.typeVars].map(prettyT).join(", ")}: ${prettyT(type.type)}`;
if (type.typeVars.size > 0) {
return `${[...type.typeVars].map(prettyT).join(", ")}: ${prettyT(type.type)}`;
}
return prettyT(type.type);
}
if (type.symbol === symbolFunction) {
return `${prettyT(type.params[0])} -> ${prettyT(type.params[1])}`;