move function
This commit is contained in:
parent
8a4bd44f04
commit
55c5d7cffa
5 changed files with 38 additions and 36 deletions
|
|
@ -2,12 +2,13 @@ import { select, number, input } from '@inquirer/prompts';
|
|||
import { ModulePoint } from "../lib/point.js";
|
||||
import { DefaultMap } from "../util/defaultmap.js";
|
||||
import { pretty } from '../util/pretty.js';
|
||||
import { isFunction, prettyT } from '../structures/types.js';
|
||||
import { isFunction } from '../structures/types.js';
|
||||
import { ModuleStd } from '../stdlib.js';
|
||||
import { Double, GenericType, Int, SymbolT, Type } from "../primitives/types.js";
|
||||
import { eqType } from '../primitives/type.js';
|
||||
import { Any } from "../primitives/types.js";
|
||||
import { assignFn, makeGeneric, onlyOccurring } from '../generics/generics.js';
|
||||
import { prettyT } from '../util/pretty.js';
|
||||
|
||||
|
||||
// import {emitKeypressEvents} from 'node:readline';
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { eqType } from "../primitives/type.js";
|
||||
import { zip } from "../util/util.js";
|
||||
import { pretty } from '../util/pretty.js';
|
||||
import { prettyT } from "../structures/types.js";
|
||||
import { prettyT } from "../util/pretty.js";
|
||||
|
||||
// constructor for generic types
|
||||
// for instance, the type:
|
||||
|
|
|
|||
|
|
@ -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(", ")})`;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,38 @@
|
|||
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, breakLength: 120 });
|
||||
}
|
||||
|
||||
// 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(", ")})`;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ import { Int } from "../primitives/types.js";
|
|||
import { enumType } from "../structures/enum.js";
|
||||
import { newProduct } from "../structures/product.js";
|
||||
import { structType } from "../structures/struct.js";
|
||||
import { prettyT, prodType } from "../structures/types.js";
|
||||
import { prodType } from "../structures/types.js";
|
||||
import { prettyT } from "../util/pretty.js";
|
||||
|
||||
const Slot = structType([
|
||||
newProduct("value")(() => Value),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue