Skip to content

Instantly share code, notes, and snippets.

Avatar

Yassine Elouafi yelouafi

View GitHub Profile
@yelouafi
yelouafi / gist:e25b8ebc7b0b52dd4268f0d7b53040e6
Last active June 8, 2022 19:04 — forked from blackslate/gist:695cf7e76348c4948db7
Demo of using project() and unproject() to drag an object parallel to the camera plane
View gist:e25b8ebc7b0b52dd4268f0d7b53040e6
<!DOCTYPE html>
<html>
<head>
<title>THREE.JS WORLD</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r73/three.js"></script>
<style>
body {
/* set margin to 0 and overflow to hidden, to
use the complete page */
View AlgJ.hs
{-# Language TypeSynonymInstances, FlexibleInstances #-}
module Algj where
import Debug.Trace
import Data.Maybe
import qualified Data.Map as M
import qualified Data.Set as S
import Control.Monad.Trans.State
View Algw.hs
{-# Language TypeSynonymInstances, FlexibleInstances #-}
module Algw where
import Data.Maybe
import qualified Data.Map as M
import qualified Data.Set as S
import Control.Monad.Trans.State
@yelouafi
yelouafi / algebraic-effects-series-4.md
Last active November 12, 2022 03:58
Implementing Algebraic Effects and Handlers
View algebraic-effects-series-4.md

Algebraic Effects in JavaScript part 4 - Implementing Algebraic Effects and Handlers

This is the final part of a series about Algebraic Effects and Handlers.

So we've come to the core topic. The reality is that we've already covered most of it in the previous parts. Especially, in the third part, where we saw delimited continuations at work.

@yelouafi
yelouafi / algebraic-effects-series-3.md
Last active June 8, 2022 03:15
Delimited Continuations
View algebraic-effects-series-3.md
@yelouafi
yelouafi / algebraic-effects-series-2.md
Last active March 14, 2022 06:40
Capturing continuations with Generators
View algebraic-effects-series-2.md

Algebraic Effects in JavaScript part 2 - Capturing continuations with Generators

This is the second part of a series about Algebraic Effects and Handlers.

Note: initially I planned a 3-part series, but since the current post on undelimited continuations ended up taking

@yelouafi
yelouafi / multishot-callcc.js
Created September 21, 2018 17:05
multi shot continuations
View multishot-callcc.js
function isGenerator(x) {
return x != null && typeof x.next === "function"
}
function isFrame(x) {
return x != null && x._type_ === 'call_frame'
}
function call(genFunc, ...args) {
@yelouafi
yelouafi / algebraic-effects-series-1.md
Last active March 2, 2023 06:31
Operational Introduction to Algebraic Effects and Continuations
View algebraic-effects-series-1.md

Algebraic Effects in JavaScript part 1 - continuations and control transfer

This is the first post of a series about Algebraic Effects and Handlers.

There are 2 ways to approach this topic:

  • Denotational: explain Algebraic Effects in terms of their meaning in mathematics/Category theory
  • Operational: explain the mechanic of Algebraic Effects by showing how they operate under a chosen runtime environment

Both approaches are valuables and give different insights on the topic. However, not everyone (including me), has the prerequisites to grasp the concepts of Category theory and Abstract Algebra. On the other hand, the operational approach is accessible to a much wider audience of programmers even if it doesn't provide the full picture.

@yelouafi
yelouafi / delimited-continuations.js
Last active August 21, 2022 07:16
delimited continuations using javascript generators
View delimited-continuations.js
// We model the call stack using a linked list of Generators
// Each Generator has a _return field pointing back to its parent
function stepGen(gen, arg) {
const {done, value} = gen.next(arg)
if(done) {
if(gen._return) {
stepGen(gen._return, value)
}
@yelouafi
yelouafi / abort.js
Last active November 29, 2020 07:40
callcc with javascript generators
View abort.js
function*example() {
const x = 10
const y = yield callcc(function*(k) {
// ...
yield k(20)
throw "Unreachable code"
})
console.log(x + y)
}