move executables to scripts

This commit is contained in:
Joeri Exelmans 2025-03-24 17:29:33 +01:00
parent 145835ad5d
commit d236eca5e5
2 changed files with 66 additions and 6 deletions

60
scripts/int_or_bool.js Normal file
View file

@ -0,0 +1,60 @@
import { assign, makeGeneric, unify } from "../generics/generics.js";
import { Bool, Int } from "../primitives/types.js";
import { constructorLeft, constructorRight, match } from "../structures/sum.js";
import { fnType, sumType } from "../structures/types.js";
import { pretty } from "../util.js";
const IntOrBool = sumType(Int)(Bool);
// console.log(int5);
console.log(pretty(unify(
makeGeneric(() => IntOrBool),
makeGeneric(a => sumType(Int)(a)),
)));
const cipFunction = (x) => {
return match(x)({
left: x_as_int => (x_as_int === 5),
right: x_as_bool => false,
});
}
const cipFunctionType = fnType
(IntOrBool) // in
(Bool);
// console.log(cipFunctionType);
// console.log(IntOrBool);
console.log(assign(
makeGeneric(() => cipFunctionType),
makeGeneric(() => IntOrBool),
));
console.log("calling constructorLeft with Int:");
const typeAtCallSite = assign(
makeGeneric((a, b) =>
fnType
(a)
(sumType(a)(b))
),
makeGeneric(() => Int));
console.log(pretty(typeAtCallSite));
console.log("calling cipFunction:");
console.log(pretty(assign(
makeGeneric(() => cipFunctionType),
typeAtCallSite,
)));
console.log("valid function calls:");
console.log(cipFunction(constructorLeft(5)));
console.log(cipFunction(constructorLeft(7)));
console.log(cipFunction(constructorRight(true)));
console.log("invalid function calls:");
console.log(cipFunction(5));
console.log(cipFunction(constructorLeft("abc")));

View file

@ -1,10 +1,10 @@
import { select } from '@inquirer/prompts'; import { select } from '@inquirer/prompts';
import { ModulePoint } from "./lib/point.js"; import { ModulePoint } from "../lib/point.js";
import { DefaultMap, pretty, prettyT } from './util.js'; import { DefaultMap, pretty, prettyT } from '../util.js';
import { symbolFunction } from './structures/types.js'; import { symbolFunction } from '../structures/types.js';
import { ModuleStd } from './stdlib.js'; import { ModuleStd } from '../stdlib.js';
import { Type } from "./primitives/types.js"; import { Type } from "../primitives/types.js";
import { assign, makeGeneric, unify } from './generics/generics.js'; import { assign, makeGeneric, unify } from '../generics/generics.js';
class Context { class Context {
constructor(mod) { constructor(mod) {