reorganize directory and file structure

This commit is contained in:
Joeri Exelmans 2025-05-07 13:44:49 +02:00
parent 1d826ea8d4
commit 48390b8556
99 changed files with 1155 additions and 1629 deletions

3
lib/primitives/double.js Normal file
View file

@ -0,0 +1,3 @@
export const addDouble = x => y => x + y;
export const mulDouble = x => y => x * y;
export const eqDouble = x => y => x === y;

View file

@ -0,0 +1,10 @@
import { getDefaultTypeParser } from "../parser/type_parser.js";
import { addDouble, eqDouble, mulDouble } from "./double.js";
const mkType = getDefaultTypeParser();
export const ModuleDouble = [
{ i: addDouble, t: mkType("Double -> Double -> Double") },
{ i: mulDouble, t: mkType("Double -> Double -> Double") },
{ i: eqDouble, t: mkType("Double -> Double -> Bool") },
];

View file

@ -0,0 +1,3 @@
export const newDynamic = i => t => ({i, t});
export const getInst = lnk => lnk.i;
export const getType = lnk => lnk.t;

View file

@ -0,0 +1,14 @@
import { getDefaultTypeParser } from "../parser/type_parser.js";
import { getInst, getType, newDynamic } from "./dynamic.js";
const mkType = getDefaultTypeParser();
export const ModuleDynamic = [
{ i: newDynamic, t: mkType("∀a: a -> Type -> Dynamic")},
// allows us to (unsafely) cast the result to the specific type...
// (not sure if this is the right way to go)
{ i: getInst, t: mkType("∀a: Dynamic -> a") },
{ i: getType, t: mkType("Dynamic -> Type") },
];

3
lib/primitives/int.js Normal file
View file

@ -0,0 +1,3 @@
export const addInt = x => y => x + y;
export const mulInt = x => y => x * y;
export const eqInt = x => y => x === y;

View file

@ -0,0 +1,10 @@
import { getDefaultTypeParser }from "../parser/type_parser.js";
import { addInt, eqInt, mulInt } from "./int.js";
const mkType = getDefaultTypeParser();
export const ModuleInt = [
{ i: addInt, t: mkType("Int -> Int -> Int") },
{ i: mulInt, t: mkType("Int -> Int -> Int") },
{ i: eqInt, t: mkType("Int -> Int -> Bool") },
];

View file

@ -0,0 +1,40 @@
// to break up dependency cycles, primitive types are defined in their own JS module
import { makeTypeConstructor } from "../meta/type_constructor.js";
export const SymbolInt = "Int__02a884563f7d480bb14c09be640dfe7a";
export const SymbolBool = "Bool__d64c4865bead40439dad62727aaaac2d";
export const SymbolDouble = "Double__be70f3c8f53f4419a7866d106faae091";
export const SymbolByte = "Byte__bf9e8453cd554e81971880ba33dc9f27";
export const SymbolChar = "Char__e47159519d3345119336b751fc8da1de";
export const SymbolUnit = "Unit__a70ca021c32a4036a594d332aedfb029";
export const SymbolBottom = "⊥__95beece951bc457781be8c5481d35dcc";
export const SymbolSymbol = "Symbol__f67c077430e04e4fa40ed2e2b2a3040d";
export const SymbolType = "Type__fdbea309d66f49b483b0dd4ceb785f7d";
export const SymbolTop = "__38709c3c0039468782103256d4730d1f";
export const SymbolGenericType = "GenericType__e9d8010b82f64206afa83d0c163df5d2";
export const SymbolDynamic = "Dynamic__3c16c415dba94228ada37dc9d446f54f";
export const Int = makeTypeConstructor(SymbolInt)(0);
export const Bool = makeTypeConstructor(SymbolBool)(0);
export const Double = makeTypeConstructor(SymbolDouble)(0);
export const Byte = makeTypeConstructor(SymbolByte)(0);
export const Char = makeTypeConstructor(SymbolChar)(0);
// Unit type has only 1 instance, the empty tuple.
export const Unit = makeTypeConstructor(SymbolUnit)(0);
// Bottom type has no instances.
export const Bottom = makeTypeConstructor(SymbolBottom)(0);
export const SymbolT = makeTypeConstructor(SymbolSymbol)(0);
// Types are typed by Top
export const Type = makeTypeConstructor(SymbolType)(0);
export const GenericType = makeTypeConstructor(SymbolGenericType)(0);
// Everything is typed by Top
export const Top = makeTypeConstructor(SymbolTop)(0);// A type-link, connecting a value to its Type.
export const Dynamic = makeTypeConstructor(SymbolDynamic)(0);

View file

@ -0,0 +1,31 @@
import { SymbolInt, SymbolT, SymbolBool, SymbolDouble, SymbolByte, SymbolChar, SymbolUnit, SymbolBottom, SymbolSymbol, SymbolType, SymbolGenericType, SymbolTop, Type, Int, Bool, Double, Byte, Char, Unit, Bottom, GenericType, Top, SymbolDynamic, Dynamic } from "./primitive_types.js";
export const ModulePrimitiveSymbols = [
{ i: SymbolInt , t: SymbolT },
{ i: SymbolBool , t: SymbolT },
{ i: SymbolDouble , t: SymbolT },
{ i: SymbolByte , t: SymbolT },
{ i: SymbolChar , t: SymbolT },
{ i: SymbolUnit , t: SymbolT },
{ i: SymbolBottom , t: SymbolT },
{ i: SymbolSymbol , t: SymbolT },
{ i: SymbolType , t: SymbolT },
{ i: SymbolGenericType , t: SymbolT },
{ i: SymbolTop , t: SymbolT },
{ i: SymbolDynamic , t: SymbolT },
];
export const ModulePrimitiveTypes = [
{ i: Int , t: Type },
{ i: Bool , t: Type },
{ i: Double , t: Type },
{ i: Byte , t: Type },
{ i: Char , t: Type },
{ i: Unit , t: Type },
{ i: Bottom , t: Type },
{ i: SymbolT , t: Type },
{ i: Type , t: Type },
{ i: GenericType , t: Type },
{ i: Top , t: Type },
{ i: Dynamic , t: Type },
];

2
lib/primitives/symbol.js Normal file
View file

@ -0,0 +1,2 @@
export const getHumanReadableName = symbol => symbol.slice(0, -34); // drop UUID
export const eqSymbol = a => b => a === b;

View file

@ -0,0 +1,9 @@
import { getDefaultTypeParser } from "../parser/type_parser.js"
import { eqSymbol, getHumanReadableName } from "./symbol.js";
const mkType = getDefaultTypeParser();
export const ModuleSymbol = [
{ i: getHumanReadableName, t: mkType("SymbolT -> String")},
{ i: eqSymbol, t: mkType("SymbolT -> SymbolT -> Bool")},
];

6
lib/primitives/type.js Normal file
View file

@ -0,0 +1,6 @@
import { compareTypes } from "../compare/type.js";
export const getSymbol = type => type.symbol;
export const getParams = type => type.params;
export const eqType = t1 => t2 => compareTypes(t1, t2) === 0;

View file

@ -0,0 +1,13 @@
// a module is just a set of typed objects
import { getDefaultTypeParser } from "../parser/type_parser.js";
import { eqType, getParams, getSymbol } from "./type.js";
const mkType = getDefaultTypeParser();
// each 'typed object' is implicitly an instance of TypeLink (defined below)
export const ModuleType = [
{i: eqType , t: mkType("Type -> Type -> Bool")},
{i: getSymbol, t: mkType("Type -> SymbolT")},
{i: getParams, t: mkType("Type -> [Type -> Type]")},
];

3
lib/primitives/unit.js Normal file
View file

@ -0,0 +1,3 @@
export const unit = {};
export const eqUnit = _ => _ => true;

View file

@ -0,0 +1,9 @@
import { getDefaultTypeParser } from "../parser/type_parser.js";
import { eqUnit, unit } from "./unit.js";
const mkType = getDefaultTypeParser();
export const ModuleUnit = [
{i: unit , t: mkType("Unit")},
{i: eqUnit, t: mkType("Unit -> Unit -> Bool")},
];