Add product and sum types

This commit is contained in:
Joeri Exelmans 2025-03-17 17:54:42 +01:00
parent 6023efc295
commit 574651ccb7
18 changed files with 209 additions and 157 deletions

View file

@ -1,4 +1,4 @@
import { fnType } from "../function_registry.js";
import { fnType } from "../type_registry.js";
import {Function} from "../metacircular.js";
// import {Typed} from "../typed.js";

View file

@ -1,30 +0,0 @@
import {Int, Bool, Double} from "../primitives/symbols.js";
import { getListType, makeListModule } from "../structures/list_common.js";
const ListOfBool = getListType(Bool);
const ListOfBoolModule = makeListModule(Bool);
const ListOfInt = getListType(Int);
const ListOfIntModule = makeListModule(Int);
const ListOfListOfInt = getListType(ListOfInt);
const ListOfListOfIntModule = makeListModule(ListOfInt);
export const ModuleLiterals = [
{i: 0n, t: Int},
{i: 42n, t: Int},
{i: false, t: Bool},
{i: 3.14159265359, t: Double},
{i: {l:[42n, 43n]}, t: ListOfInt},
// {i: [[42n, 43n]], t: ListOfListOfInt},
// i'm lazy
...ListOfIntModule,
// ...ListOfBoolModule,
// ...ListOfListOfIntModule,
];

View file

@ -2,7 +2,7 @@ import {Function, getIn, getOut} from "../metacircular.js";
import {Module} from "../structures/module.js";
import { deepEqual } from "../util.js";
import { Typed } from "../typed.js";
import { fnType } from "../function_registry.js";
import { fnType } from "../type_registry.js";
// import {Num, NumDict, getType, getMul} from "../typeclasses/num.js";

33
lib/values.js Normal file
View file

@ -0,0 +1,33 @@
import {Int, Bool, Double} from "../primitives/symbols.js";
import { makeListModule } from "../structures/list_common.js";
import { makeProductType } from "../structures/product.js";
import { makeSumType } from "../structures/sum.js";
import { getListType, prodType, sumType } from "../type_registry.js";
const ListOfInt = getListType(Int);
const ListOfIntModule = makeListModule(Int);
const ListOfListOfInt = getListType(ListOfInt);
const ListOfListOfIntModule = makeListModule(ListOfInt);
export const ModuleValues = [
{i: 0n, t: Int},
{i: 42n, t: Int},
{i: false, t: Bool},
{i: 3.14159265359, t: Double},
{i: {l:[42n, 43n]} , t: ListOfInt},
{i: {l:[{l:[42n, 43n]}, {l:[999n]}]}, t: ListOfListOfInt},
// i'm lazy
...ListOfIntModule,
...ListOfListOfIntModule,
...makeProductType(Int, Bool),
...makeSumType(Int, Bool),
{i: {left: 42n, right: true}, t: prodType(Int, Bool)},
{i: {variant: "L", value: 100n}, t: sumType(Int, Bool)},
];