dope2/typeclasses/eq.js
Joeri Exelmans 8eec5b9239 recursive types (and operations on them, like pretty-printing, comparison and unification) seem to be working.
big part of the code base still needs to be 'ported' to the updated type constructors.
2025-05-05 17:17:45 +02:00

43 lines
1.1 KiB
JavaScript

import { makeGeneric } from "../generics/generics";
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_dict";
export const getEq = numDict => numDict.eq;
export const ModuleEq = {l:[
// type constructor: Type -> Type
...typedFnType(eqDictType, fnType => fnType(() => Type)(() => Type)),
// (EqDict a) -> a -> a -> Bool
...typedFnType(getEq, fnType =>
makeGeneric(a =>
fnType
(eqDictType(a))
(fnType
(a)
(fnType
(a)
(Bool)
)
)), GenericType),
]};
// all our data (and types) are encoded such that we can test equality the same way:
const eq = x => y => deepEqual(x,y);
const eqDict = {eq};
export const EqInstances = new Map([
[Int , eqDict],
[Bool , eqDict],
[Double , eqDict],
[Byte , eqDict],
[Char , eqDict],
[Unit , eqDict],
[Type , eqDict],
[SymbolT, eqDict],
]);