move file
This commit is contained in:
parent
fc1a588e23
commit
ce192b49f2
2 changed files with 32 additions and 27 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import { Bool, Int } from "./primitives/symbols.js";
|
import { Bool, Int } from "../primitives/symbols.js";
|
||||||
import { fnType, lsType } from "./type_registry.js";
|
import { fnType, lsType } from "../type_registry.js";
|
||||||
import { deepEqual } from "./util.js";
|
import { deepEqual } from "../util.js";
|
||||||
|
|
||||||
export const makeGeneric = callback => {
|
export const makeGeneric = callback => {
|
||||||
// type variables to make available:
|
// type variables to make available:
|
||||||
|
|
@ -152,27 +152,3 @@ export const assign = (genFnType, paramType) => {
|
||||||
type: substitutedOutType,
|
type: substitutedOutType,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// a -> Int
|
|
||||||
const a_to_Int = makeGeneric(a => fnType({in: a, out: Int}));
|
|
||||||
const Bool_to_Int = fnType({in: lsType(Bool), out: Int});
|
|
||||||
console.log(matchConcrete(a_to_Int, Bool_to_Int));
|
|
||||||
|
|
||||||
// (a -> a) -> b
|
|
||||||
const fnType2 = makeGeneric((a,b) => fnType({in: fnType({in: a, out: a}), out: b}));
|
|
||||||
// (Bool -> Bool) -> a
|
|
||||||
const fnType3 = makeGeneric(a => fnType({in: fnType({in: Bool, out: Bool}), out: a}));
|
|
||||||
console.log(matchGeneric(fnType2, fnType3));
|
|
||||||
|
|
||||||
// (a -> b) -> [a] -> [b]
|
|
||||||
const mapFnType = makeGeneric((a,b) =>
|
|
||||||
fnType({
|
|
||||||
in: fnType({in: a, out: b}),
|
|
||||||
out: fnType({in: lsType(a), out: lsType(b)}),
|
|
||||||
}));
|
|
||||||
// a -> a
|
|
||||||
const idFnType = makeGeneric(a =>
|
|
||||||
fnType({in: a, out: a}));
|
|
||||||
|
|
||||||
// should be: [a] -> [a]
|
|
||||||
console.log(assign(mapFnType, idFnType));
|
|
||||||
29
generics/generics.test.js
Normal file
29
generics/generics.test.js
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
import { Bool, Int } from "../primitives/symbols.js";
|
||||||
|
import { fnType, lsType } from "../type_registry.js";
|
||||||
|
import { assign, makeGeneric, matchConcrete, matchGeneric } from "./generics.js";
|
||||||
|
|
||||||
|
// a -> Int
|
||||||
|
const a_to_Int = makeGeneric(a => fnType({in: a, out: Int}));
|
||||||
|
// Bool -> Int
|
||||||
|
const Bool_to_Int = fnType({in: lsType(Bool), out: Int});
|
||||||
|
// should be: Bool -> Int
|
||||||
|
console.log(matchConcrete(a_to_Int, Bool_to_Int));
|
||||||
|
|
||||||
|
// (a -> a) -> b
|
||||||
|
const fnType2 = makeGeneric((a,b) => fnType({in: fnType({in: a, out: a}), out: b}));
|
||||||
|
// (Bool -> Bool) -> a
|
||||||
|
const fnType3 = makeGeneric(a => fnType({in: fnType({in: Bool, out: Bool}), out: a}));
|
||||||
|
// should be: (Bool -> Bool) -> a
|
||||||
|
console.log(matchGeneric(fnType2, fnType3));
|
||||||
|
|
||||||
|
// (a -> b) -> [a] -> [b]
|
||||||
|
const mapFnType = makeGeneric((a,b) =>
|
||||||
|
fnType({
|
||||||
|
in: fnType({in: a, out: b}),
|
||||||
|
out: fnType({in: lsType(a), out: lsType(b)}),
|
||||||
|
}));
|
||||||
|
// a -> a
|
||||||
|
const idFnType = makeGeneric(a =>
|
||||||
|
fnType({in: a, out: a}));
|
||||||
|
// should be: [a] -> [a]
|
||||||
|
console.log(assign(mapFnType, idFnType));
|
||||||
Loading…
Add table
Add a link
Reference in a new issue