Skip to content

Instantly share code, notes, and snippets.

View tel's full-sized avatar
✍️

Joseph Abrahamson tel

✍️
View GitHub Profile
@tel
tel / Hf.scala
Created June 14, 2016 06:55
Higher-order free constructions in Scala
import scala.language.higherKinds
trait Tc1 {
type T[_]
}
trait Functor extends Tc1 {
def map[A, B](f: A => B)(ta: T[A]): T[B]
}
@tel
tel / AbstractModel.scala
Created March 14, 2016 02:38
Beautiful "Graphs" signature example from Martin Odersky's "Scala: The Simple Parts"
/**
* Partially (!) specializes Graphs signature.
*
* Note that Node and Edge are still abstract! We add new
* functionality by concretely specifying Graph, but the DSL
* still works in its limited initial form since newGraph abstracted
* over Graph construction
*
*/
@tel
tel / Elm.scala
Created March 3, 2016 22:18
Scala.js Elm-alike
package tutorial.webapp
import japgolly.scalajs.react._
import japgolly.scalajs.react.vdom.prefix_<^._
import org.scalajs.dom
import scala.scalajs.js.JSApp
trait Component {
type Params
@tel
tel / Corec.hs
Created January 30, 2016 00:37
Constraints and Corecords
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
@tel
tel / Sums.js
Created August 4, 2015 16:33
Sums in Javascript
/*
"Concrete" sums are by default open. They are values of the form
{ variant: String, params: {[String]: *} }
*/
/**
@tel
tel / Rou.hs
Created July 26, 2015 03:26
Rou(ting)
{-# LANGUAGE TypeOperators, TupleSections, LambdaCase, RecordWildCards, RankNTypes #-}
module Rou where
import Control.Lens
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Monoid
import Control.Monad
import Control.Applicative
@tel
tel / ProfunctorLens.js
Last active October 23, 2023 20:32
Pure Profunctor Lenses in Javascript (redux)
/* eslint-disable new-cap */
/**
* Lens types.
* ===========
*
* a * b = {fst: a, snd: b}
* a + b = {index: Boolean, value: a | b}
*
* Iso s t a b = forall (~>) . Profunctor (~>) => (a ~> b) -> (s ~> t)
@tel
tel / Profunctor.js
Last active April 3, 2019 01:51
"Pure-profunctor" lenses in Javascript (!)
/// PRELIMINARIES
/**
* Generalized "products" of any size. For gluing things together. A tuple is a
* "2"-meet.
*
* The type `Meet a b c d ...` indicates a `Meet` of the given size with values
* at each type in the sequence.
*/
@tel
tel / Lens.js
Created June 20, 2015 05:06
Really simple van Laarhoven lenses in Javascript
const IdModule = {
fmap: (fn) => (x) => fn(x),
}
const ConstModule = {
fmap: (fn) => (x) => x,
}
/**
@tel
tel / Cont.js
Created June 4, 2015 04:24
Continuation monad in Javascript
function Cont(contHandler) {
this.contHandler = contHandler;
};
Cont.unit = function(value) {
return new Cont(function (continue) { return continue(value); });
};
Cont.prototype.run = function(resume) {
return this.contHandler(resume);