Skip to content

Instantly share code, notes, and snippets.

Avatar

Yassine Elouafi yelouafi

View GitHub Profile
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
View index.md

Network Requests

There are a few ways to get info from an API


What is await?

const response = await fetch("mysite.com/api/dogs")
@yelouafi
yelouafi / algebraic-effects-series-4.md
Last active Oct 24, 2020
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 Nov 26, 2020
Delimited Continuations
View algebraic-effects-series-3.md
@yelouafi
yelouafi / algebraic-effects-series-2.md
Last active Oct 24, 2020
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 Sep 21, 2018
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 Nov 26, 2020
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 Jun 25, 2020
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 Nov 29, 2020
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)
}
You can’t perform that action at this time.