replace 'prompt' example by 'environment'
This commit is contained in:
parent
f8008aa25d
commit
b1c2e7836d
15 changed files with 317 additions and 517 deletions
|
|
@ -18,6 +18,13 @@ export const set = dict => key => value => new RBTreeWrapper(dict.tree.remove(ke
|
|||
export const remove = dict => key => new RBTreeWrapper(dict.tree.remove(key), inspectDict);
|
||||
export const length = dict => dict.tree.length;
|
||||
|
||||
export const fold = callback => initial => dict => {
|
||||
let acc = initial;
|
||||
for (const iter=dict.tree.begin; iter !== undefined && iter.valid; iter.next()) {
|
||||
acc = callback(acc)(iter.key)(iter.value);
|
||||
}
|
||||
}
|
||||
|
||||
export const first = dict => dict.tree.begin;
|
||||
export const last = dict => dict.tree.end;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { makeTypeParser } from "../parser/type_parser.js";
|
||||
import { makeTypeConstructor } from "../meta/type_constructor.js";
|
||||
import { emptyDict, first, has, last, length, read, remove, set } from "./dict.js";
|
||||
import { emptyDict, first, fold, has, last, length, read, remove, set } from "./dict.js";
|
||||
import { newDynamic } from "../primitives/dynamic.js";
|
||||
|
||||
export const symbolDictIterator = 'DictIterator__d9d175b6bfd1283f00851a99787d0499';
|
||||
|
|
@ -13,12 +13,13 @@ const mkType = makeTypeParser({
|
|||
});
|
||||
|
||||
export const ModuleDict = [
|
||||
newDynamic(emptyDict )(mkType("(a -> a -> Int) -> (a => b)") ),
|
||||
newDynamic(has )(mkType("(a => b) -> a -> Bool")),
|
||||
newDynamic(set )(mkType("(a => b) -> a -> b -> (a => b)")),
|
||||
newDynamic(remove )(mkType("(a => b) -> a -> (a => b)")),
|
||||
newDynamic(length )(mkType("(a => b) -> Int")),
|
||||
newDynamic(first )(mkType("(a => b) -> (a |=>| b)")),
|
||||
newDynamic(last )(mkType("(a => b) -> (a |=>| b)")),
|
||||
newDynamic(read )(mkType("(a |=>| b) -> (Unit + ((a*b) * (a |=>| b)))")),
|
||||
newDynamic(emptyDict)(mkType("(a -> a -> Int) -> (a => b) ")),
|
||||
newDynamic(has )(mkType("(a => b) -> a -> Bool ")),
|
||||
newDynamic(set )(mkType("(a => b) -> a -> b -> (a => b) ")),
|
||||
newDynamic(remove )(mkType("(a => b) -> a -> (a => b) ")),
|
||||
newDynamic(length )(mkType("(a => b) -> Int ")),
|
||||
newDynamic(fold )(mkType("(c -> a -> b -> c) -> c -> (a => b) -> c ")),
|
||||
newDynamic(first )(mkType("(a => b) -> (a |=>| b) ")),
|
||||
newDynamic(last )(mkType("(a => b) -> (a |=>| b) ")),
|
||||
newDynamic(read )(mkType("(a |=>| b) -> (Unit + ((a*b) * (a |=>| b)))")),
|
||||
];
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ export const push = ls => elem => ls.concat([elem]);
|
|||
export const pop = ls => ls.pop();
|
||||
export const map = ls => fn => ls.map(elem => fn(elem));
|
||||
export const length = ls => ls.length;
|
||||
export const fold = ls => callback => initial => {
|
||||
export const fold = callback => initial => ls => {
|
||||
let acc = initial;
|
||||
for (let i=0; i<ls.length; i++) {
|
||||
acc = callback(acc)(ls[i]);
|
||||
|
|
|
|||
|
|
@ -12,5 +12,5 @@ export const ModuleList = [
|
|||
newDynamic(pop )(mkType("[a] -> a")),
|
||||
newDynamic(map )(mkType("[a] -> (a -> b) -> [b]")),
|
||||
newDynamic(length )(mkType("[a] -> Int")),
|
||||
newDynamic(fold )(mkType("[a] -> (b -> a -> b) -> b -> b")),
|
||||
newDynamic(fold )(mkType("(b -> a -> b) -> b -> [a] -> b")),
|
||||
];
|
||||
|
|
|
|||
|
|
@ -19,11 +19,10 @@ export const add = set => key => set.tree.get(key) === true ? set : new RBTreeWr
|
|||
export const remove = set => key => new RBTreeWrapper(set.tree.remove(key), inspectSet);
|
||||
export const length = set => set.tree.length;
|
||||
|
||||
export const fold = set => callback => initial => {
|
||||
export const fold = callback => initial => set => {
|
||||
let acc = initial;
|
||||
let iter = set.tree.begin;
|
||||
while (iter !== undefined && iter.valid) {
|
||||
acc = callback(acc, iter.key);
|
||||
for (const iter=set.tree.begin; iter !== undefined && iter.valid; iter.next()) {
|
||||
acc = callback(acc)(iter.key);
|
||||
}
|
||||
return acc;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,17 +8,18 @@ export const symbolSetIterator = 'SetIterator__f6b0ddd78ed41c58e5a442f2681da011'
|
|||
const setIterator = makeTypeConstructor(symbolSetIterator)(1);
|
||||
|
||||
const mkType = makeTypeParser({
|
||||
// extra syntax to represent a set iterator:
|
||||
extraBracketOperators: [['<', ['>', setIterator]]],
|
||||
});
|
||||
|
||||
export const ModuleSet = [
|
||||
newDynamic(emptySet )(mkType("(a -> a -> Int) -> {a}") ),
|
||||
newDynamic(has )(mkType("{a} -> a -> Bool")),
|
||||
newDynamic(add )(mkType("{a} -> a -> {a}")),
|
||||
newDynamic(remove )(mkType("{a} -> a -> {a}")),
|
||||
newDynamic(length )(mkType("{a} -> Int")),
|
||||
newDynamic(fold )(mkType("{a} -> (b -> a -> b) -> b")),
|
||||
newDynamic(first )(mkType("{a} -> <a>")),
|
||||
newDynamic(last )(mkType("{a} -> <a>")),
|
||||
newDynamic(read )(mkType("<a> -> (Unit + (a * <a>))")),
|
||||
newDynamic(emptySet)(mkType("(a -> a -> Int) -> {a}" )),
|
||||
newDynamic(has )(mkType("{a} -> a -> Bool" )),
|
||||
newDynamic(add )(mkType("{a} -> a -> {a}" )),
|
||||
newDynamic(remove )(mkType("{a} -> a -> {a}" )),
|
||||
newDynamic(length )(mkType("{a} -> Int" )),
|
||||
newDynamic(fold )(mkType("(b -> a -> b) -> b -> {a} -> b")),
|
||||
newDynamic(first )(mkType("{a} -> <a>" )),
|
||||
newDynamic(last )(mkType("{a} -> <a>" )),
|
||||
newDynamic(read )(mkType("<a> -> (Unit + (a * <a>))" )),
|
||||
];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue