move function
This commit is contained in:
parent
8a4bd44f04
commit
55c5d7cffa
5 changed files with 38 additions and 36 deletions
|
|
@ -52,36 +52,3 @@ export const lsType = makeTypeConstructor(symbolList)(1);
|
|||
|
||||
export const symbolSet = Symbol('Set');
|
||||
export const setType = makeTypeConstructor(symbolSet)(1);
|
||||
|
||||
|
||||
// Pretty print type
|
||||
export function prettyT(type) {
|
||||
// console.log("pretty:", type);
|
||||
if (typeof type === "symbol") {
|
||||
return type.description;
|
||||
}
|
||||
if (type.typeVars) {
|
||||
if (type.typeVars.size > 0) {
|
||||
return `∀${[...type.typeVars].map(prettyT).sort((a,b)=>a.localeCompare(b)).join(",")}: ${prettyT(type.type)}`;
|
||||
}
|
||||
else {
|
||||
return 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