type inferencing "unifying" operation is now bi-directional + begin writing generic version of "unifying" operation (that should work on all types)
This commit is contained in:
parent
c5ac55b0ff
commit
33c156fc5c
5 changed files with 148 additions and 9 deletions
|
|
@ -2,6 +2,7 @@ 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 { getMul, NumInstances } from "./num.js";
|
||||
import { numDictType } from "./num_type.js";
|
||||
|
||||
const square = numDict => x => getMul(numDict)(x)(x);
|
||||
|
|
@ -21,3 +22,7 @@ console.log(assign(squareFnType, makeGeneric(() => numDictType(Int))));
|
|||
// should be: Double -> Double
|
||||
console.log(assign(squareFnType, makeGeneric(() => numDictType(Double))));
|
||||
|
||||
// to call 'square' we need:
|
||||
// - access to a mapping from types to their typeclass instantiation
|
||||
// - to know that our argument is 'Int'
|
||||
console.log(square(NumInstances.get(Int))(42n)); // 1764n
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue