add String type + use String to make nominal types unique (worse, but more pleasant when debugging)
This commit is contained in:
parent
18b5e56ff0
commit
9405ba1b4e
9 changed files with 41 additions and 13 deletions
19
lib/point.js
19
lib/point.js
|
|
@ -1,17 +1,21 @@
|
||||||
import { Function, Type } from "../metacircular.js";
|
import { Function, Type } from "../metacircular.js";
|
||||||
import { Double } from "../primitives/symbols.js";
|
import { Double } from "../primitives/symbols.js";
|
||||||
|
import { String } from "../structures/list_types/string.js";
|
||||||
import { nominalType, NominalType } from "../structures/nominal_type.js";
|
import { nominalType, NominalType } from "../structures/nominal_type.js";
|
||||||
|
import { makeProductType } from "../structures/product.js";
|
||||||
import { fnType, prodType, typedFnType } from "../type_registry.js";
|
import { fnType, prodType, typedFnType } from "../type_registry.js";
|
||||||
|
|
||||||
const PointCartesian2D = nominalType(
|
const PointCartesian2D = nominalType(
|
||||||
// just a unique number, to make sure that our type is only equal to itself
|
// just a unique number, to make sure that our type is only equal to itself
|
||||||
BigInt("0xBBAAD62B10EE21993BA690A732DA2A6875CE4B6F5E7139D5AEC9FD887F9D24A8"))
|
"PointCartesian2D")
|
||||||
(prodType(Double, Double));
|
// BigInt("0xBBAAD62B10EE21993BA690A732DA2A6875CE4B6F5E7139D5AEC9FD887F9D24A8"))
|
||||||
|
(prodType(String, Double));
|
||||||
|
|
||||||
const PointPolar2D = nominalType(
|
const PointPolar2D = nominalType(
|
||||||
// just a unique number, to make sure that our type is only equal to itself
|
// just a unique number, to make sure that our type is only equal to itself
|
||||||
BigInt("0x31CDAB4B3D84C4EB27D3C111FD7580E533268B72E05BD694F8B262913E018B72"))
|
"PointPolar2D")
|
||||||
(prodType(Double, Double));
|
// BigInt("0x31CDAB4B3D84C4EB27D3C111FD7580E533268B72E05BD694F8B262913E018B72"))
|
||||||
|
(prodType(String, Double));
|
||||||
|
|
||||||
export const cart2polar = ({left: x, right: y}) => {
|
export const cart2polar = ({left: x, right: y}) => {
|
||||||
const r = Math.sqrt(x*x + y*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: θ};
|
return {left: r+dr, right: θ};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const examplePoint = {left: 1, right: 2};
|
||||||
|
|
||||||
export const ModulePoint = {l:[
|
export const ModulePoint = {l:[
|
||||||
{i: -1 , t: Double},
|
{i: -1 , t: Double},
|
||||||
{i: 2 , 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: PointCartesian2D , t: NominalType},
|
||||||
{i: PointPolar2D , t: NominalType},
|
{i: PointPolar2D , t: NominalType},
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import {Function, getIn, getOut} from "../metacircular.js";
|
import {Function, getIn, getOut} from "../metacircular.js";
|
||||||
import {Module} from "../structures/module.js";
|
import {Module} from "../structures/list_types/module.js";
|
||||||
import { deepEqual } from "../util.js";
|
import { deepEqual } from "../util.js";
|
||||||
import { Typed } from "../typed.js";
|
import { Typed } from "../typed.js";
|
||||||
import { fnType } from "../type_registry.js";
|
import { fnType } from "../type_registry.js";
|
||||||
|
|
|
||||||
2
main.js
2
main.js
|
|
@ -7,7 +7,7 @@ import { makeSquare } from "./lib/square.js";
|
||||||
import {makeIdFn} from "./lib/id.js";
|
import {makeIdFn} from "./lib/id.js";
|
||||||
|
|
||||||
import {DefaultMap, pretty} from "./util.js";
|
import {DefaultMap, pretty} from "./util.js";
|
||||||
import { ModuleModule } from "./structures/module.js";
|
import { ModuleModule } from "./structures/list_types/module.js";
|
||||||
import { ModuleList } from "./structures/list.js";
|
import { ModuleList } from "./structures/list.js";
|
||||||
import {Int, Bool, Double, Byte} from "./primitives/symbols.js";
|
import {Int, Bool, Double, Byte} from "./primitives/symbols.js";
|
||||||
import { makeListModule } from "./structures/list_common.js";
|
import { makeListModule } from "./structures/list_common.js";
|
||||||
|
|
|
||||||
11
primitives/char.js
Normal file
11
primitives/char.js
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { typedFnType } from "../type_registry.js";
|
||||||
|
import {Type} from "../metacircular.js";
|
||||||
|
import {Char, Bool} from "./symbols.js";
|
||||||
|
|
||||||
|
const eq = x => y => x === y;
|
||||||
|
|
||||||
|
export const ModuleChar = {l:[
|
||||||
|
{i: Char, t: Type},
|
||||||
|
|
||||||
|
...typedFnType(eq, fnType => fnType({in: Char, out: fnType({in: Char, out: Bool})})),
|
||||||
|
]};
|
||||||
|
|
@ -4,3 +4,4 @@ export const Bool = Symbol('Bool');
|
||||||
export const Int = Symbol('Int');
|
export const Int = Symbol('Int');
|
||||||
export const Double = Symbol('Double');
|
export const Double = Symbol('Double');
|
||||||
export const Byte = Symbol('Byte');
|
export const Byte = Symbol('Byte');
|
||||||
|
export const Char = Symbol('Char');
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { fnType, lsType } from "../type_registry.js";
|
import { fnType, lsType } from "../type_registry.js";
|
||||||
import {Type, Function} from "../metacircular.js";
|
import {Type, Function} from "../metacircular.js";
|
||||||
import { makeListModule } from "./list_common.js";
|
import { makeListModule } from "./list_common.js";
|
||||||
import { Module } from "./module.js";
|
import { Module } from "./list_types/module.js";
|
||||||
|
|
||||||
const Type_to_Type = fnType({in: Type, out: Type});
|
const Type_to_Type = fnType({in: Type, out: Type});
|
||||||
const Type_to_Module = fnType({in: Type, out: Module});
|
const Type_to_Module = fnType({in: Type, out: Module});
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { makeListModule } from "./list_common.js";
|
import { makeListModule } from "../list_common.js";
|
||||||
import { Typed } from "../typed.js";
|
import { Typed } from "../../typed.js";
|
||||||
import { lsType } from "../type_registry.js";
|
import { lsType } from "../../type_registry.js";
|
||||||
|
|
||||||
export const Module = lsType(Typed); // a Module is a list of Typeds
|
export const Module = lsType(Typed); // a Module is a list of Typeds
|
||||||
|
|
||||||
7
structures/list_types/string.js
Normal file
7
structures/list_types/string.js
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { Char } from "../../primitives/symbols.js";
|
||||||
|
import { lsType } from "../../type_registry.js";
|
||||||
|
import { makeListModule } from "../list_common.js";
|
||||||
|
|
||||||
|
export const String = lsType(Char);
|
||||||
|
|
||||||
|
export const ModuleString = makeListModule(Char);
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { fnType, prodType, sumType } from "../type_registry.js";
|
import { fnType, prodType, sumType } from "../type_registry.js";
|
||||||
import { Function, Type } from "../metacircular.js";
|
import { Function, Type } from "../metacircular.js";
|
||||||
import { Module } from "./module.js";
|
import { Module } from "./list_types/module.js";
|
||||||
|
|
||||||
const constructorLeft = left => ({variant: "L", value: left });
|
const constructorLeft = left => ({variant: "L", value: left });
|
||||||
const constructorRight = right => ({variant: "R", value: right});
|
const constructorRight = right => ({variant: "R", value: right});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue