Skip to content
Parser Combinators, Maybe, Either, State, Reader, StateMaybe, StateEither in JavaScript and in ECMAScript 6
JavaScript HTML Other
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
es6 eval0 implemented up to Plus (included) Nov 3, 2019
haskell little refurbishing in the Haskell area Oct 6, 2019
img
io first real io functor stuff Apr 18, 2019
js minor stuff Aug 14, 2016
parsers-node strange commit Aug 29, 2019
parsers
.editorconfig editorconfig and its beneficial effects May 3, 2018
.gitattributes Initial Commit Aug 8, 2013
.gitignore adjusting .gitignores Jun 7, 2019
LICENSE License file Sep 20, 2014
MochaGeiesmonadsES6_Reader_Test.htm
MochaGeiesmonadsES6_StateEither_Test.htm minor thingies Apr 23, 2017
MochaGeiesmonadsES6_StateMaybe_Test.htm better data on supported browsers Oct 14, 2015
MochaGeiesmonadsES6_Test.htm better data on supported browsers Oct 14, 2015
README.md Update README.md Dec 16, 2018
YUIGeiesmonads_TRAIN_Test.htm major refurbishment - ES6 rulez Oct 4, 2015
YUIGeiesmonads_Test.htm major refurbishment - ES6 rulez Oct 4, 2015

README.md

geiesmonads (j-s-monads)

alt image

Crisp clear chainable JavaScript/ECMAScript 6 monads.

Special Challenge: parser combinators in JavaScript!!!

File parsers.js contains an implementation of chainable parser combinators, featuring both applicative and monadic interfaces.

Test page is here.

Live examples page is here.

A JSON parser is under construction, and it is tested here.

NB - with a big credit due to Understanding Parser Combinators and to Paco.

New with RELEASE 2.2

File geiesmonads_es6_reader.js contains an implementation of a chainable reader monad.

Test page is here.

NB - with a big credit due to Don't Fear the Reader.

New with RELEASE 2.1

Maybe, Either a, State, StateMaybe and StateEither in ECMAScript 6.

Click on the above links to access the Mocha unit test page (verify whether your browser can run the code).

NB: This repo has been tested on FF 41 and Chrome 57.

Define a State monad that manages errors (in a sense like Maybe): if an error/problem occurs during the "do" computation, it is signalled and propagated by bind.

  • Step 1) The presence of a None indicates an error has occurred -> StateMaybe monad
  • Step 2) The error should propagate carrying a string which describes what occurred -> StateEither monad

See files:

New with RELEASE 2.0

  • Minor improvements to the maybe monad:
    • introduction of inner functions some() and none()
    • streamlining of the API
  • Major improvements to the state monad:
    • monad as pure JS function - see [7]
  • Implementation of monadic labeling for a binary tree and its comparison with manual labeling. See [4]
  • Usage of the state monad to emulate imperative programming - see [5]

TRAINING

ORIGINAL CONTRIBUTION: Implementation of a chainable state monad.

This monad is a native JS function with type s -> (s,a) enriched with a bind method. The present JS implementation of [4] is also available in Java 8 language at [6]

See file geiesmonads_0.2.js and related tests.

DEBITS AND CREDITS

  • The non-chainable identity, maybe and state monad are just repetitions of implementations given in [2] and [3]

  • The chainable maybe monad is a re-elaboration of some old code of mine, written in Java and available at my blog

  • My original contribution (the chainable state monad) is a truly cool thing.

I am in debt with:

[2] http://jabberwocky.eu/2012/11/02/monads-for-dummies/

[3] http://igstan.ro/posts/2011-05-02-understanding-monads-with-javascript.html

I am in DEEP debt with:

[1] http://james-iry.blogspot.it/2007/09/monads-are-elephants-part-1.html (and also part 2,3,4)

[4] http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad

[5] http://brandon.si/code/the-state-monad-a-tutorial-for-the-confused/

A bit of self-promotion:

[6] http://faustinelli.wordpress.com/2014/04/25/the-state-monad-in-java-8-eventually/

[7] http://faustinelli.wordpress.com/2014/06/01/state-monad-goes-to-js-town-and-starts-swinging/

Every feedback is welcome.


Released under MIT License.

You can’t perform that action at this time.