This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// # Lambda as JS, or A Flock of Functions | |
// ### Combinators, Lambda Calculus, and Church Encodings in JavaScript | |
// #### Notes for [a talk by Gabriel Lebec | |
// (click for videos and slides)](https://www.youtube.com/watch?v=3VQ382QG-y4&list=PLpkHU923F2XFWv-XfVuvWuxq41h21nOPK&index=1) | |
const chalk = require('chalk') | |
const green = chalk.green.bind(chalk) | |
const red = chalk.red.bind(chalk) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Either | |
data Term = TTrue | |
| TFalse | |
| TIf Term Term Term | |
| TZero | |
| TSucc Term | |
| TPred Term | |
| TIsZero Term |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cons = (x, y) => (m) => m(x, y) | |
const car = (z) => z((p, q) => p) | |
const cdr = (z) => z((p, q) => q) | |
const someLinkedList = cons(1, cons(2, cons(3 , null))) | |
// iterating |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const makeMonad = (prevData, prevLog) => fn => { | |
const newData = fn(prevData).data; | |
const newLog = prevLog + fn(prevData).log; | |
return { data: newData, | |
log: newLog, | |
bind: makeMonad(newData, newLog) | |
}; | |
}; | |
const pure = x => ({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("@babel/polyfill") | |
const { implement, Functor } = require("@masaeedu/fp") | |
const Fluture= require("fluture") | |
// We can just get map from of and chain for free everywhere | |
const deriveFunctor = implement(Functor) | |
// Identity monad | |
const id = x => x; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fibs(n) { | |
let [last, curr] = [0, 1]; | |
for (let i = 0; i < n; i++) { | |
[last, curr] = [curr, last + curr]; | |
} | |
return last; // think: why isn't this `curr`? | |
} | |
// fibs(3) | |
// 0 1 3 4 7 | |
// 0 1 1 2 3 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Fluture= require("fluture") | |
// We can just get map from of and chain for free everywhere | |
const deriveFunctor = M => ({ ...M, map: f => M.chain(x => M.of(f(x))) }) | |
// Identity monad | |
const id = x => x; | |
const Identity = deriveFunctor({ of: id, chain: id }); | |
const Maybe = (() => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Either | |
data Term = TTrue | |
| TFalse | |
| TIf Term Term Term | |
| TZero | |
| TSucc Term | |
| TPred Term | |
| TIsZero Term |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (module.hot) { | |
module.hot.accept('./components/root/RootComponent.js', () => { | |
const FdyRootComponent = require('./components/root/RootComponent.js').FdyRootComponent | |
ReactDOM.unmountComponentAtNode(node) | |
ReactDOM.render( | |
<Provider store={store}> | |
<RouterProvider router={router.routerInstance}> | |
<FdyRootComponent /> | |
</RouterProvider> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Reader(x) { | |
this.x = x; | |
} | |
Reader.prototype.run = function(env) { | |
return this.x(env); | |
} | |
Reader.of = function(x) { | |
return new Reader(() => x); |