reorganize directory and file structure
This commit is contained in:
parent
1d826ea8d4
commit
48390b8556
99 changed files with 1155 additions and 1629 deletions
|
|
@ -1,45 +1,37 @@
|
|||
import { Bool, Int } from "../primitives/types.js";
|
||||
import { fnType, lsType } from "../structures/types.js";
|
||||
import { assign, makeGeneric, unify } from "../generics/generics.js";
|
||||
import { prettyGenT, prettyT } from "../util/pretty.js";
|
||||
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();
|
||||
|
||||
// a -> Int
|
||||
const a_to_Int = makeGeneric(a => fnType(() => a)(() => Int));
|
||||
console.log((prettyGenT(a_to_Int))); // ∀a: (a -> Int)
|
||||
// Bool -> Int
|
||||
const Bool_to_Int = makeGeneric(() => fnType(() => lsType(() =>Bool))(() => Int));
|
||||
console.log((prettyGenT(Bool_to_Int))); // ∀: ([Bool] -> Int)
|
||||
console.log("should be: [Bool] -> Int")
|
||||
console.log(prettyGenT(unify(a_to_Int, Bool_to_Int)));
|
||||
console.log(prettyGenT(
|
||||
unify(
|
||||
mkType("∀a: (a -> Int)"),
|
||||
makeGeneric(() => mkType("[Bool] -> Int")),
|
||||
)
|
||||
));
|
||||
|
||||
// (a -> a) -> b
|
||||
const fnType2 = makeGeneric((a,b) => fnType(() => fnType(a)(a))(() => b));
|
||||
// (Bool -> Bool) -> a
|
||||
const fnType3 = makeGeneric(a => fnType(() => fnType(Bool)(Bool))(() => a));
|
||||
console.log("should be: (Bool -> Bool) -> a");
|
||||
console.log(prettyT(unify(fnType2, fnType3)));
|
||||
console.log(prettyGenT(
|
||||
unify(
|
||||
mkType("∀a,b: (a -> a) -> b"),
|
||||
mkType("∀a: (Bool -> Bool) -> a"),
|
||||
)
|
||||
));
|
||||
|
||||
// (a -> b) -> [a] -> [b]
|
||||
const mapFnType = makeGeneric((a,b) =>
|
||||
fnType
|
||||
(fnType(() => a)(() => b))
|
||||
(fnType(() => lsType(() =>a))(() => lsType(() =>b))))
|
||||
// a -> a
|
||||
const idFnType = makeGeneric((_,__,c) =>
|
||||
fnType(() => c)(() => c));
|
||||
console.log("should be: [c] -> [c]");
|
||||
console.log(prettyT(assign(mapFnType, idFnType)));
|
||||
console.log("should be: [a] -> [a]");
|
||||
console.log(prettyGenT(
|
||||
assign(
|
||||
mkType("∀a,b: (a -> b) -> [a] -> [b]"),
|
||||
mkType("∀a: a -> a")
|
||||
)
|
||||
));
|
||||
|
||||
// (a -> Int) -> [a] -> a
|
||||
const weirdFnType = makeGeneric(a =>
|
||||
fnType
|
||||
(fnType(() => a)(() => Int))
|
||||
(fnType
|
||||
(lsType(() =>a))
|
||||
(a)))
|
||||
// we call this function with parameter of type (b -> b) ...
|
||||
// giving these substitutions:
|
||||
// a := b
|
||||
// b := Int
|
||||
console.log("should be: [Int] -> Int");
|
||||
console.log(prettyT(assign(weirdFnType, idFnType)));
|
||||
console.log(prettyGenT(
|
||||
assign(
|
||||
mkType("∀a: (a -> Int) -> [a] -> a"),
|
||||
mkType("∀a: a -> a")
|
||||
)
|
||||
));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue