Skip to content
This repository has been archived by the owner on May 4, 2020. It is now read-only.
/ MACwMP Public archive

Monadic array comprehension with meta programming in JS

License

Notifications You must be signed in to change notification settings

hatashiro/MACwMP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MACwMP

Monadic array comprehension with meta programming in JS

What's this?

Implementation of Haskell-like array comprehension, probabily in the most eccentric way.

$[x + y | x <- [1, 2, 3], y <- [4, 5, 6], x * y % 2 === 0]
// -> [ 5, 7, 6, 7, 8, 7, 9 ]

How does it work?

  1. With Sweet.js, define a macro for array comprehension operator $.
  2. The macro builds array comprehension into async/await syntax.
  3. Replace global Promise with CArray (stands for comprehensible array)
  4. Build async/await syntax into Promise chaining
    • Do expression in Haskell can also be transformed into bind chaining
  5. Profit!

Run examples

npm run build -- examples/simple.js
node dist/simple.js

You can see each build step with each build script.

# build macro
./scripts/build-macro.sh examples/simple.js
cat dist/simple.macro.js

# build async/await into Promise chaining with Babel
./scripts/build-babel.sh dist/simple.macro.js
cat dist/simple.babel.js

# concat monad stuff
./scripts/build-monad.sh dist/simple.babel.js
cat dist/simple.js

License

MIT

Releases

No releases published

Packages

No packages published