branching and very basic merging of slots
This commit is contained in:
parent
614e6c0fdb
commit
3978f7f835
32 changed files with 684 additions and 420 deletions
|
|
@ -3,7 +3,7 @@ import { GenericType, SymbolT, Type, Unit } from "../primitives/types";
|
|||
import { typedFnType } from "../structures/types";
|
||||
import { Bool, Byte, Char, Double, Int } from "../primitives/types";
|
||||
import { deepEqual } from "../util/util";
|
||||
import { eqDictType } from "./eq_type";
|
||||
import { eqDictType } from "./eq_dict";
|
||||
|
||||
export const getEq = numDict => numDict.eq;
|
||||
|
||||
|
|
|
|||
4
typeclasses/eq_dict.js
Normal file
4
typeclasses/eq_dict.js
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import { makeTypeConstructor } from "../type_constructor.js";
|
||||
|
||||
const eqDictSymbol = Symbol('EqDict');
|
||||
export const eqDictType = makeTypeConstructor(eqDictSymbol)(1);
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
import { DefaultMap } from "../util/defaultmap.js";
|
||||
|
||||
const eqDictSymbol = Symbol('EqDict');
|
||||
const eqDictTypeRegistry = new DefaultMap(a => ({
|
||||
symbol: eqDictSymbol,
|
||||
params: [a],
|
||||
}));
|
||||
export const eqDictType = a => eqDictTypeRegistry.getdefault(a, true);
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
import { assign } from "../generics/generics.js";
|
||||
import { makeGeneric } from "../generics/generics.js";
|
||||
import { Double, Int } from "../primitives/types.js";
|
||||
import { fnType } from "../structures/types.js";
|
||||
import { pretty } from '../util/pretty.js';
|
||||
import { getMul, NumInstances } from "./num.js";
|
||||
import { numDictType } from "./num_type.js";
|
||||
|
||||
const square = numDict => x => getMul(numDict)(x)(x);
|
||||
|
||||
// NumDict a -> a -> a
|
||||
const squareFnType = makeGeneric(a =>
|
||||
fnType
|
||||
(numDictType(a))
|
||||
(fnType(a)(a))
|
||||
);
|
||||
|
||||
console.log("should be: Int -> Int");
|
||||
console.log(pretty(assign(squareFnType, makeGeneric(() => numDictType(Int)))));
|
||||
|
||||
console.log("should be: Double -> Double");
|
||||
console.log(pretty(assign(squareFnType, makeGeneric(() => numDictType(Double)))));
|
||||
|
||||
// to call 'square' we need:
|
||||
// - the type of our argument (=Int)
|
||||
// - access to a mapping from types to their typeclass instantiation
|
||||
console.log("");
|
||||
console.log(square(NumInstances.get(Int))(42n)); // 1764n
|
||||
4
typeclasses/num_dict.js
Normal file
4
typeclasses/num_dict.js
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import { makeTypeConstructor } from "../type_constructor.js";
|
||||
|
||||
const numDictSymbol = Symbol("NumDict");
|
||||
export const numDictType = makeTypeConstructor(numDictSymbol)(1);
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
import { DefaultMap } from "../util/defaultmap.js";
|
||||
|
||||
const numDictSymbol = Symbol("NumDict");
|
||||
const numDictTypeRegistry = new DefaultMap(a => ({
|
||||
symbol: numDictSymbol,
|
||||
params: [a],
|
||||
}));
|
||||
export const numDictType = a => numDictTypeRegistry.getdefault(a, true);
|
||||
9
typeclasses/show.js
Normal file
9
typeclasses/show.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { cart2Str, NPoint2DCartesian, NPoint2DPolar, polar2Str } from "../lib/point.js";
|
||||
import { Type } from "../primitives/types.js";
|
||||
import { prettyT } from "../structures/types.js";
|
||||
|
||||
export const ShowInstances = new Map([
|
||||
[Type , {show: prettyT}],
|
||||
[NPoint2DCartesian, {show: cart2Str}],
|
||||
[NPoint2DPolar , {show: polar2Str}],
|
||||
]);
|
||||
5
typeclasses/show_dict.js
Normal file
5
typeclasses/show_dict.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { makeTypeConstructor } from "../type_constructor.js";
|
||||
|
||||
const showDictSymbol = Symbol('ShowDict');
|
||||
export const showDictType = makeTypeConstructor(showDictSymbol)(1);
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue