mattbierner / akh Goto Github PK
View Code? Open in Web Editor NEWJavascript Monad and Monad Transformer Collection
License: MIT License
Javascript Monad and Monad Transformer Collection
License: MIT License
Instance classes currently define things like:
State.chain = \c f -> ...
But these can only be used with State computations
A version of chain
that works with any type of computation (determined by the argument value) should also be provided.
Trampoline thunks do not need to create anon functions. Curring is 2x+ slower than anon functions but better would be just passing the f
and possible arg to thunk
and inlining the application of the thunk with a single args in Trampoline.run
thunk(\-> runStateT(c, s))
would become
thunk(c.run, s)
Calls of appk
to run
from the inner monad still can explode the stack with the proper computation.
When execute the example in the README.md, it produce the following result:
[ { x: 'state1xyzaa', s: 'state1xyz' },
{ x: '3aa', s: 'new_state' } ]
But it should be:
[
{'x': '1aa', 's': 'state1xyz'},
{'x': '3aa', 's': 'new_state'},
{'x': '10aa', 's': 'state1xyz'}
{'x': 'state1xyzaa', 's': 'state1xyz'}
]
I think by calling put
it should only change s
not x
The way it is used in khepri-compile, this is degrading performance without any benefit
But DContT
may need to wrap.
Certain ops, mainly the state ops, should be automatically lifted if available.
DCont already has the entire implementation so we may as well split it into its own public package.
It's very hard to contribute across Akh monads:
core.spec
), they need to check out every repo (currently 11) plus the base repo to make the changesThere are some great tools for managing monorepos (e.g. lerna).
Proposed migration with lerna
:
lerna
package within the base Akh package3.2.0
), and lerna
is operated in Fixed modeI'm happy to help with the migration, or even open an initial PR myself -- just want to check with you before spending a lot of time on this
Bennu currently defines two parser late
and rec
that would be useful as a more general solution for Akh monads
Late resolves the content of function only when a computation is actually run.
var a;
// `a` is not defined yet but we don't care since it is resolved when `c` is run
var c = M.late(\-> a).map(+, 10);
a = M.of 3;
run c; // 13
Rec allows references to itself and is defined using late
rec = \def -> {
var value = def <| late\->value;
return value;
};
var c = rec \ self -> M.get.chain(\x -> x > 10 : M.of x : M.modify(+, 1).concat(self))
As shorthand for applying to functions with multiple args since we lack haskell's auto currying.
The most direct solution currently is
of(\x -> \y -> x + y)
.ap(1)
.ap(3);
or
of(curry (+))
.ap(1)
.ap(3);
But this ac
would be better because it would enable the programmer to explicitly control when arguments are curried vs when they are applied (every reasonable implementation of curry
will not work for n-ary functions).
of(+)
.ac(1)
.ap(3);
Or for a n-ary function
of(console.log)
.ac('many')
.ac('many')
.ac('many')
.ac('many')
.ac('arguments')
.ap('wow');
Hi,
according to the documentation, monad constructors resulting from transformations should be equipped with the liftInner()
method. I did the following:
let EitherT = require('akh').trans.either,
Task = require('data.task'),
EitherTask = EitherT(Task);
Given the following function:
let getGreetings = name => Task.of('hey: ' + name);
I would expect to be able to lift getGreetings
by doing:
EitherTask.liftInner(getGreetings);
Unfortunately, on node 5.0.0 I get:
TypeError: EitherTask.liftInner is not a function
Am I missing something?
Thanks!
Some of these implementations will blow up the stack for large computations.
Without types, for a stack of transformers, there needs to be a better way to lift the value of inner transformer from the outer one.
N = (StateT Unique);
M = ErrorT N;
To lift unique
, you currently have to do
M.lift <| N.lift <| Unique.unique;
For larger stacks, this would be better:
M.liftInner <| Unique.unique;
Where lift inner defined in the outer transformer as the composition of lift
on m
and regular lift
.
Currently, operations like chain are using a extra call because the operation is specified as a regular function. The chain
on an existing structure therefore requires capturing the current this
object and passing it to the regular function. Reversing this behavior would be more efficient since ops like chain
are almost always used as methods instead of regular functions.
Hi,
I would like to ask if it is possible to double each example with its JavaScript counterpart (both in the website and the wiki). I'm confident AKH can prove very useful when coupled with the Folktale libraries, but I'm having a hard time following the examples because of the Khepri syntax.
Thanks.
Hi there,
I'm discovering the fantasy land ecosystem and i was wondering if Akh would work with fantasy-do and how would lifting work?
Cheers,
Jun
EitherT is not wrapping all of its results in a trampoline so it can enter an inf loop.
Would use Either #2
This will break the current stack safe impl of State by default.
The solution will be to wrap the entire monad (instead of every level) in a codensity. It may be worth providing a convenience function that does Codensity (StateT m)
too.
When using the prototype form of State.run
: State.prototype.run
(e.g. State.of('something').run('whatever')
), the operation fails with a cryptic error message:
TypeError: k is not a function
at Object.f (node_modules/akh.codensity/trans/codensity.js:24:32)
at Object.module.exports.tail.module.exports.trampoline.f [as trampoline] (node_modules/akh.codensity/node_modules/akh.core.trampoline/index.js:21:23)
at Function.spec.Monad.spec.Monoid.spec.Transformer.CodensityT.run (node_modules/akh.codensity/trans/codensity.js:60:11)
at spec.Monad.spec.Monoid.spec.Transformer.Instance.run (node_modules/akh.codensity/trans/codensity.js:47:27)
at Context.<anonymous> (tests/state.js:21:15)
State.prototype.run
works fine when used from akh.state
directly.
See PR #33 for a failing test
Verified the issues exists for the following node versions:
0.12
4.0.0
4.8.4
8.0.0
8.2.1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.