dope2/examples/generics.js

37 lines
872 B
JavaScript

import { assign, makeGeneric, unify } from "../lib/generics/generics.js";
import { prettyGenT } from "../lib/util/pretty.js";
import { getDefaultTypeParser } from "../lib/parser/type_parser.js";
const mkType = getDefaultTypeParser();
console.log("should be: [Bool] -> Int")
console.log(prettyGenT(
unify(
mkType("∀a: (a -> Int)"),
makeGeneric(() => mkType("[Bool] -> Int")),
)
));
console.log("should be: (Bool -> Bool) -> a");
console.log(prettyGenT(
unify(
mkType("∀a,b: (a -> a) -> b"),
mkType("∀a: (Bool -> Bool) -> a"),
)
));
console.log("should be: [a] -> [a]");
console.log(prettyGenT(
assign(
mkType("∀a,b: (a -> b) -> [a] -> [b]"),
mkType("∀a: a -> a")
)
));
console.log("should be: [Int] -> Int");
console.log(prettyGenT(
assign(
mkType("∀a: (a -> Int) -> [a] -> a"),
mkType("∀a: a -> a")
)
));