add String type + use String to make nominal types unique (worse, but more pleasant when debugging)

This commit is contained in:
Joeri Exelmans 2025-03-20 14:09:17 +01:00
parent 18b5e56ff0
commit 9405ba1b4e
9 changed files with 41 additions and 13 deletions

View file

@ -1,17 +1,21 @@
import { Function, Type } from "../metacircular.js";
import { Double } from "../primitives/symbols.js";
import { String } from "../structures/list_types/string.js";
import { nominalType, NominalType } from "../structures/nominal_type.js";
import { makeProductType } from "../structures/product.js";
import { fnType, prodType, typedFnType } from "../type_registry.js";
const PointCartesian2D = nominalType(
// just a unique number, to make sure that our type is only equal to itself
BigInt("0xBBAAD62B10EE21993BA690A732DA2A6875CE4B6F5E7139D5AEC9FD887F9D24A8"))
(prodType(Double, Double));
"PointCartesian2D")
// BigInt("0xBBAAD62B10EE21993BA690A732DA2A6875CE4B6F5E7139D5AEC9FD887F9D24A8"))
(prodType(String, Double));
const PointPolar2D = nominalType(
// just a unique number, to make sure that our type is only equal to itself
BigInt("0x31CDAB4B3D84C4EB27D3C111FD7580E533268B72E05BD694F8B262913E018B72"))
(prodType(Double, Double));
"PointPolar2D")
// BigInt("0x31CDAB4B3D84C4EB27D3C111FD7580E533268B72E05BD694F8B262913E018B72"))
(prodType(String, Double));
export const cart2polar = ({left: x, right: y}) => {
const r = Math.sqrt(x*x + y*y);
@ -37,10 +41,15 @@ export const scale = dr => ({left: r, right: θ}) => {
return {left: r+dr, right: θ};
}
const examplePoint = {left: 1, right: 2};
export const ModulePoint = {l:[
{i: -1 , t: Double},
{i: 2 , t: Double},
{i: {left: 1, right: 2}, t: PointCartesian2D},
{i: examplePoint , t: PointCartesian2D},
{i: examplePoint , t: prodType(Double, Double)},
...makeProductType(Double, Double).l,
{i: PointCartesian2D , t: NominalType},
{i: PointPolar2D , t: NominalType},