interactive prompt
This commit is contained in:
parent
bc91d9bf39
commit
3596e01c28
9 changed files with 298 additions and 105 deletions
25
util.js
25
util.js
|
|
@ -47,7 +47,30 @@ 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});
|
||||
}
|
||||
}
|
||||
|
||||
export function prettyT(type) {
|
||||
if (type.typeVars) {
|
||||
return `∀${[...type.typeVars].map(prettyT).join(", ")}: ${prettyT(type.type)}`;
|
||||
}
|
||||
if (type.symbol === symbolFunction) {
|
||||
return `${prettyT(type.params[0])} -> ${prettyT(type.params[1])}`;
|
||||
}
|
||||
if (type.symbol === symbolList) {
|
||||
return `[${prettyT(type.params[0])}]`;
|
||||
}
|
||||
if (type.symbol === symbolProduct) {
|
||||
return `(${prettyT(type.params[0])}, ${prettyT(type.params[1])})`;
|
||||
}
|
||||
if (type.symbol === symbolSum) {
|
||||
return `(${prettyT(type.params[0])} | ${prettyT(type.params[1])})`;
|
||||
}
|
||||
if (type.params.length === 0) {
|
||||
return type.symbol.description;
|
||||
}
|
||||
return `${type.symbol.description}(${type.params.map(prettyT).join(", ")})`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue