Compare commits

...

1 Commits

Author SHA1 Message Date
alex 912f755d03 try using bind rather than applicative in register 2025-06-29 23:18:50 +01:00
+14 -3
View File
@@ -46,10 +46,11 @@ export class Pattern {
* @param {function} query - The function that maps a `State` to an array of `Hap`.
* @noAutocomplete
*/
constructor(query, steps = undefined) {
constructor(query, steps = undefined, alignment = undefined) {
this.query = query;
this._Pattern = true; // this property is used to detectinstance of another Pattern
this._steps = steps; // in terms of number of steps per cycle
this._alignment = alignment;
}
get _steps() {
@@ -76,6 +77,11 @@ export class Pattern {
return this._steps !== undefined;
}
setAlignment(alignment) {
this._alignment = alignment;
return this;
}
//////////////////////////////////////////////////////////////////////
// Haskell-style functor, applicative and monadic operations
@@ -1610,8 +1616,13 @@ export function register(name, func, patternify = true, preserveSteps = false, j
let mapFn = (...args) => {
return func(...args, pat);
};
mapFn = curry(mapFn, null, arity - 1);
result = join(right.reduce((acc, p) => acc.appLeft(p), left.fmap(mapFn)));
// mapFn = curry(mapFn, null, arity - 1);
// result = join(right.reduce((acc, p) => acc.appLeft(p), left.fmap(mapFn)));
// patternify2 f pata patb patc = pata >>= \a -> patb >>= \b -> f a b patc
function bindArgs(argv, pat, ...pats) {
return pat.innerBind((x) => (pats.length ? bindArgs([...argv, x], ...pats) : mapFn(...argv, x)));
}
result = bindArgs([], ...firstArgs);
}
}
if (preserveSteps) {