Code Monkey home page Code Monkey logo

akh's People

Contributors

b-gran avatar dtipson avatar janvogt avatar joneshf avatar mattbierner avatar vlmonk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

akh's Issues

Generic Versions of Top Level ops

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.

Inline trampoline thunk logic

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)

Still can Blow Up stack

Calls of appk to run from the inner monad still can explode the stack with the proper computation.

State put modifies x

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

Autolifting

Certain ops, mainly the state ops, should be automatically lifted if available.

Unique

DCont already has the entire implementation so we may as well split it into its own public package.

Create a monorepo containing all of the Akh monads

Proposal: move Akh to a monorepo

Why?

It's very hard to contribute across Akh monads:

  • Changes to one monad may affect others (some tests depend on other monads)
  • The main Akh package must manually keep versions of child packages up-to-date (this has caused bugs in the past)
  • If one wants to add e.g. a new prototype method to all transformers (that can't go on core.spec), they need to check out every repo (currently 11) plus the base repo to make the changes

How?

There are some great tools for managing monorepos (e.g. lerna).

Proposed migration with lerna:

  • Each Akh monad is a lerna package within the base Akh package
  • Initially (and for backwards compatibility) each Akh monad is still published as its own package
  • The versions of all Akh monads are bumped to the version of Akh (say 3.2.0), and lerna is operated in Fixed mode

What do you think about moving to a monorepo? We're still able to publish individual packages for each monad (if this is something people are using).

I'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

Late and Rec

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))

ac

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');

M.liftInner()

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!

Tail Calls

Some of these implementations will blow up the stack for large computations.

Transformer liftInner

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.

Make member methods default

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.

JavaScript examples

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.

Do notation

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

Remove Trampoline

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.

State.run failing on State instances

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.