progress
This commit is contained in:
parent
6af72e525c
commit
145835ad5d
22 changed files with 153 additions and 90 deletions
|
|
@ -1,29 +1,28 @@
|
|||
import { assign } from "../generics/generics.js";
|
||||
import { makeGeneric } from "../generics/generics.js";
|
||||
import { fnType } from "../structures/function.js";
|
||||
import { Double, Int } from "../primitives/types.js";
|
||||
import { fnType } from "../structures/types.js";
|
||||
import { pretty } from "../util.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({
|
||||
in: numDictType(a),
|
||||
out: fnType({
|
||||
in: a,
|
||||
out: a,
|
||||
}),
|
||||
}));
|
||||
fnType
|
||||
(numDictType(a))
|
||||
(fnType(a)(a))
|
||||
);
|
||||
|
||||
console.log("should be: Int -> Int");
|
||||
console.log(assign(squareFnType, makeGeneric(() => numDictType(Int))));
|
||||
console.log(pretty(assign(squareFnType, makeGeneric(() => numDictType(Int)))));
|
||||
|
||||
console.log("should be: Double -> Double");
|
||||
console.log(assign(squareFnType, makeGeneric(() => numDictType(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
|
||||
// - to know that our argument is 'Int'
|
||||
console.log("");
|
||||
console.log(square(NumInstances.get(Int))(42n)); // 1764n
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue