progress with type classes, type inference still very ad-hoc
This commit is contained in:
parent
5283be608b
commit
c5ac55b0ff
10 changed files with 64 additions and 19 deletions
23
typeclasses/num.test.js
Normal file
23
typeclasses/num.test.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { assign } from "../generics/generics.js";
|
||||
import { makeGeneric } from "../generics/generics.js";
|
||||
import { fnType } from "../metacircular.js";
|
||||
import { Double, Int } from "../primitives/symbols.js";
|
||||
import { numDictType } from "./num_type.js";
|
||||
|
||||
const square = numDict => x => getMul(numDict)(x)(x);
|
||||
|
||||
const squareFnType = makeGeneric(a =>
|
||||
fnType({
|
||||
in: numDictType(a),
|
||||
out: fnType({
|
||||
in: a,
|
||||
out: a,
|
||||
}),
|
||||
}));
|
||||
|
||||
// should be: Int -> Int
|
||||
console.log(assign(squareFnType, makeGeneric(() => numDictType(Int))));
|
||||
|
||||
// should be: Double -> Double
|
||||
console.log(assign(squareFnType, makeGeneric(() => numDictType(Double))));
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue