Skip to content

Instantly share code, notes, and snippets.

View ameobin's full-sized avatar

ameobin ameobin

  • retrojected
View GitHub Profile

Monads and delimited control are very closely related, so it isn’t too hard to understand them in terms of one another. From a monadic point of view, the big idea is that if you have the computation m >>= f, then f is m’s continuation. It’s the function that is called with m’s result to continue execution after m returns.

If you have a long chain of binds, the continuation is just the composition of all of them. So, for example, if you have

m >>= f >>= g >>= h

then the continuation of m is f >=> g >=> h. Likewise, the continuation of m >>= f is g >=> h.

@samuelfvlcastro
samuelfvlcastro / 32bitpacking.js
Last active April 22, 2024 20:59
Example of a bit field in javascript. Packing RGBA values into a single 32bit integer
function logBinary(number){
console.log((number >>> 0).toString(2).replace(/(.{8})/g, " "));
}
var startBit = 8;
var bitsToGet = 8;
var alpha = 45;
var red = 187;
var green = 255;
var blue = 56;