This commit is contained in:
Joeri Exelmans 2025-03-24 17:28:07 +01:00
parent 6af72e525c
commit 145835ad5d
22 changed files with 153 additions and 90 deletions

View file

@ -1,7 +1,7 @@
import { makeGeneric } from "../generics/generics.js";
import { addDouble, mulDouble } from "../primitives/double.js";
import { addInt, mulInt } from "../primitives/int.js";
import { Type } from "../type.js";
import { Type } from "../primitives/types.js";
import { typedFnType, typedFnType2 } from "../structures/types.js";
import { Double, Int } from "../primitives/types.js";
import { numDictType } from "./num_type.js";
@ -10,14 +10,15 @@ export const getAdd = numDict => numDict.add;
export const getMul = numDict => numDict.mul;
// getAdd and getMul have same (generic) type:
// NumDict a -> a -> a -> a
const [getAddMulFnType, typesOfFns] = typedFnType2(fnType =>
makeGeneric(a => fnType({
in: numDictType(a),
out: fnType({
in: a,
out: fnType({in: a, out: a}),
}),
})));
makeGeneric(a =>
fnType
(numDictType(a))
(fnType
(a)
(fnType(a)(a))
)));
export const ModuleNum = {l:[
...typedFnType(numDictType, fnType => fnType({in: Type, out: Type})),
@ -51,4 +52,4 @@ export const ModuleNumInstances = {l:[
export const NumInstances = new Map([
[Int , IntNumDict ],
[Double, DoubleNumDict],
]);
]);