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.
This commit is contained in:
parent
55c5d7cffa
commit
8eec5b9239
34 changed files with 523 additions and 295 deletions
|
|
@ -17,7 +17,7 @@ export const enumType = variants => {
|
|||
}
|
||||
const [variant, ...rest] = variants;
|
||||
const variantType = getRight(variant);
|
||||
return sumType(variantType)(enumType(rest));
|
||||
return sumType(() => variantType)(() => enumType(rest));
|
||||
};
|
||||
|
||||
const eatParameters = (numParams, result) => {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { Dynamic } from "../primitives/dynamic.js"
|
|||
|
||||
// 'normal' implementation
|
||||
export const emptyList = {l:[]};
|
||||
const emptyListType = makeGeneric(a => lsType(a));
|
||||
// const emptyListType = makeGeneric(a => lsType(() => a));
|
||||
export const get = ls => i => ls.l[i];
|
||||
export const put = ls => i => elem => ({l: ls.l.with(Number(i), elem)});
|
||||
export const push = ls => elem => ({l:ls.l.concat([elem])});
|
||||
|
|
@ -21,62 +21,62 @@ export const fold = ls => callback => initial => {
|
|||
return acc;
|
||||
}
|
||||
|
||||
export const String = lsType(Char); // alias
|
||||
export const Module = lsType(Dynamic);
|
||||
export const String = lsType(() =>Char); // alias
|
||||
export const Module = lsType(() =>Dynamic);
|
||||
|
||||
export const ModuleList = {l:[
|
||||
// Type -> Type
|
||||
...typedFnType(lsType, fnType =>
|
||||
fnType
|
||||
/* in */ (Type)
|
||||
/* out */ (Type)
|
||||
),
|
||||
// // Type -> Type
|
||||
// ...typedFnType(lsType, fnType =>
|
||||
// fnType
|
||||
// /* in */ (Type)
|
||||
// /* out */ (Type)
|
||||
// ),
|
||||
|
||||
// [a]
|
||||
{i: emptyList, t: emptyListType},
|
||||
{i: emptyListType, t: GenericType},
|
||||
// // [a]
|
||||
// // {i: emptyList, t: emptyListType},
|
||||
// // {i: emptyListType, t: GenericType},
|
||||
|
||||
// [a] -> Int -> a
|
||||
...typedFnType(get, fnType =>
|
||||
makeGeneric(a =>
|
||||
fnType
|
||||
/* in */ (lsType(a))
|
||||
/* out */ (fnType
|
||||
/* in */ (Int)
|
||||
/* out */ (a)
|
||||
)), GenericType),
|
||||
// // [a] -> Int -> a
|
||||
// ...typedFnType(get, fnType =>
|
||||
// makeGeneric(a =>
|
||||
// fnType
|
||||
// /* in */ (() => lsType(() => a))
|
||||
// /* out */ (() => fnType
|
||||
// /* in */ (() => Int)
|
||||
// /* out */ (() => a)
|
||||
// )), GenericType),
|
||||
|
||||
// [a] -> Int -> a -> [a]
|
||||
...typedFnType(put, fnType =>
|
||||
makeGeneric(a =>
|
||||
fnType
|
||||
/* in */ (lsType(a))
|
||||
/* out */ (fnType
|
||||
/* in */ (Int)
|
||||
/* out */ (fnType
|
||||
/* in */ (a)
|
||||
/* out */ (lsType(a))
|
||||
)
|
||||
)), GenericType),
|
||||
// // [a] -> Int -> a -> [a]
|
||||
// ...typedFnType(put, fnType =>
|
||||
// makeGeneric(a =>
|
||||
// fnType
|
||||
// /* in */ (() => lsType(() => a))
|
||||
// /* out */ (() => fnType
|
||||
// /* in */ (() => Int)
|
||||
// /* out */ (() => fnType
|
||||
// /* in */ (() => a)
|
||||
// /* out */ (() => lsType(() => a))
|
||||
// )
|
||||
// )), GenericType),
|
||||
|
||||
// [a] -> a -> [a]
|
||||
...typedFnType(push, fnType =>
|
||||
makeGeneric(a =>
|
||||
fnType
|
||||
(lsType(a))
|
||||
(fnType
|
||||
(a)
|
||||
(lsType(a))
|
||||
)
|
||||
), GenericType),
|
||||
// // [a] -> a -> [a]
|
||||
// ...typedFnType(push, fnType =>
|
||||
// makeGeneric(a =>
|
||||
// fnType
|
||||
// (() => lsType(() => a))
|
||||
// (() => fnType
|
||||
// (() => a)
|
||||
// (() => lsType(() => a))
|
||||
// )
|
||||
// ), GenericType),
|
||||
|
||||
// [a] -> (a -> b) -> [b]
|
||||
...typedFnType(map, fnType =>
|
||||
makeGeneric((a, b) =>
|
||||
fnType
|
||||
(lsType(a))
|
||||
(fnType
|
||||
(fnType(a)(b))
|
||||
(lsType(b))
|
||||
)), GenericType),
|
||||
// // [a] -> (a -> b) -> [b]
|
||||
// ...typedFnType(map, fnType =>
|
||||
// makeGeneric((a, b) =>
|
||||
// fnType
|
||||
// (() => lsType(() => a))
|
||||
// (() => fnType
|
||||
// (() => fnType(() => a)(() => b))
|
||||
// (() => lsType(() => b))
|
||||
// )), GenericType),
|
||||
]};
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ export const ModuleProduct = {l: [
|
|||
(a)
|
||||
(fnType
|
||||
(b)
|
||||
(prodType(a)(b))
|
||||
(prodType(() => a)(() => b))
|
||||
)
|
||||
), GenericType),
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ export const ModuleProduct = {l: [
|
|||
...typedFnType(getLeft, fnType =>
|
||||
makeGeneric((a, b) =>
|
||||
fnType
|
||||
(prodType(a)(b))
|
||||
(prodType(() => a)(() => b))
|
||||
(a)
|
||||
), GenericType),
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ export const ModuleProduct = {l: [
|
|||
...typedFnType(getRight, fnType =>
|
||||
makeGeneric((a, b) =>
|
||||
fnType
|
||||
(prodType(a)(b))
|
||||
(prodType(() => a)(() => b))
|
||||
(b)
|
||||
), GenericType),
|
||||
]};
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ export class RBTreeWrapper {
|
|||
// (a -> a -> Int) -> Set(a)
|
||||
export const emptySet = compareFn => new RBTreeWrapper(createRBTree((x, y) => compareFn(x)(y)));
|
||||
|
||||
// const emptySetType = makeGeneric(a => fnType(fnType(a)(fnType(a)(Int)))(setType(a)));
|
||||
// const emptySetType = makeGeneric(a => fnType(() => fnType(a)(fnType(a)(Int)))(() => set(() => a)));
|
||||
|
||||
export const has = set => key => set.tree.get(key) === true;
|
||||
export const add = set => key => set.tree.get(key) === true ? set : new RBTreeWrapper(set.tree.insert(key, true));
|
||||
|
|
@ -57,7 +57,7 @@ export const ModuleSet = {l:[
|
|||
// ...typedFnType(has, fnType =>
|
||||
// makeGeneric(a =>
|
||||
// fnType
|
||||
// /* in */ (setType(a))
|
||||
// /* in */ (set(() => a))
|
||||
// /* out */ (fnType
|
||||
// /* in */ (a)
|
||||
// /* out */ (Bool)
|
||||
|
|
@ -66,9 +66,9 @@ export const ModuleSet = {l:[
|
|||
// ...typedFnType(add, fnType =>
|
||||
// makeGeneric(a =>
|
||||
// fnType
|
||||
// /* in */ (setType(a))
|
||||
// /* in */ (set(() => a))
|
||||
// /* out */ (fnType
|
||||
// /* in */ (a)
|
||||
// /* out */ (setType(a))
|
||||
// /* out */ (set(() => a))
|
||||
// )), GenericType),
|
||||
]};
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export const structType = fields => {
|
|||
}
|
||||
const [field, ...rest] = fields;
|
||||
const fieldType = getRight(field);
|
||||
return prodType(fieldType)(structType(rest));
|
||||
return prodType(() => fieldType)(() => structType(rest));
|
||||
};
|
||||
|
||||
export const makeConstructor = fields => {
|
||||
|
|
@ -41,7 +41,7 @@ export const makeConstructorType = type => fields => {
|
|||
}
|
||||
const [field, ...rest] = fields;
|
||||
const fieldType = getRight(field);
|
||||
return fnType(fieldType)(makeConstructorType(rest));
|
||||
return fnType(() => fieldType)(() => makeConstructorType(rest));
|
||||
};
|
||||
|
||||
export const makeGetters = fields => {
|
||||
|
|
@ -60,6 +60,6 @@ export const makeGetters = fields => {
|
|||
export const makeGettersTypes = type => fields => {
|
||||
return fields.map(field => {
|
||||
const fieldType = getRight(field);
|
||||
return fnType(type)(fieldType);
|
||||
return fnType(() => type)(() => fieldType);
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -23,40 +23,40 @@ export const ModuleSum = {l:[
|
|||
// Type -> Type -> Type
|
||||
...typedFnType(sumType, fnType =>
|
||||
fnType
|
||||
(Type)
|
||||
(fnType
|
||||
(Type)
|
||||
(Type)
|
||||
(() => Type)
|
||||
(() => fnType
|
||||
(() => Type)
|
||||
(() => Type)
|
||||
),
|
||||
),
|
||||
|
||||
// a -> a | b
|
||||
...typedFnType(newLeft, fnType =>
|
||||
makeGeneric((a, b) =>
|
||||
fnType
|
||||
(a)
|
||||
(sumType(a)(b))
|
||||
), GenericType),
|
||||
// // a -> a | b
|
||||
// ...typedFnType(newLeft, fnType =>
|
||||
// makeGeneric((a, b) =>
|
||||
// fnType
|
||||
// (a)
|
||||
// (sumType(() => a)(() => b))
|
||||
// ), GenericType),
|
||||
|
||||
// b -> a | b
|
||||
...typedFnType(newRight, fnType =>
|
||||
makeGeneric((a, b) =>
|
||||
fnType
|
||||
(b)
|
||||
(sumType(a)(b))
|
||||
), GenericType),
|
||||
// // b -> a | b
|
||||
// ...typedFnType(newRight, fnType =>
|
||||
// makeGeneric((a, b) =>
|
||||
// fnType
|
||||
// (b)
|
||||
// (sumType(() => a)(() => b))
|
||||
// ), GenericType),
|
||||
|
||||
// a | b -> (a -> c, b-> c) -> c
|
||||
...typedFnType(match, fnType =>
|
||||
makeGeneric((a, b, c) =>
|
||||
fnType
|
||||
(sumType(a)(b))
|
||||
(fnType
|
||||
(prodType
|
||||
(fnType(a)(c))
|
||||
(fnType(b)(c))
|
||||
)
|
||||
(c)
|
||||
)
|
||||
), GenericType),
|
||||
// // a | b -> (a -> c, b-> c) -> c
|
||||
// ...typedFnType(match, fnType =>
|
||||
// makeGeneric((a, b, c) =>
|
||||
// fnType
|
||||
// (() => sumType(() => a)(() => b))
|
||||
// (() => fnType
|
||||
// (() => prodType
|
||||
// (() => fnType(() => a)(() => c))
|
||||
// (() => fnType(() => b)(() => c))
|
||||
// )
|
||||
// (() => c)
|
||||
// )
|
||||
// ), GenericType),
|
||||
]};
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export const isFunction = type => getSymbol(type) === symbolFunction;
|
|||
export const typedFnType = (instance, callback, typeOfType = Type) => {
|
||||
const fnTs = [];
|
||||
const wrappedFnType = inType => outType => {
|
||||
const fnT = fnType(inType)(outType);
|
||||
const fnT = fnType(() => inType)(() => outType);
|
||||
fnTs.push(fnT);
|
||||
return fnT;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue