Skip to content

Instantly share code, notes, and snippets.

View tel's full-sized avatar
✍️

Joseph Abrahamson tel

✍️
View GitHub Profile
@tel
tel / recur.ml
Last active March 25, 2017 19:47
Not as bad as I feared
module type Functor = sig
type 'a t
val map : ('a -> 'b) -> ('a t -> 'b t)
end
module Mu (F : Functor) : sig
type t = { mu : t F.t }
val cata : ('a F.t -> 'a) -> (t -> 'a)
end = struct
@tel
tel / Maia.hs
Created March 18, 2017 18:46
Maia in Haskell
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
@tel
tel / CommsExample.scala
Created November 2, 2016 19:50
Comms example
// Given an interface like
sealed trait Mult
sealed trait One extends Mult
sealed trait ZeroOrOne extends Mult
sealed trait Many extends Mult
case class NoParam()
@tel
tel / Nimber.scala
Created July 8, 2016 12:10
Scala Nimbers
import scala.language.implicitConversions
class Nimber(val value: BigInt) extends AnyVal {
def size: Int = {
val bitSize =
if (value == 1) 0
else if (value <= 3) 1
else value.bitLength - 1
val logBits =
@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 / GettingToTesser.hs
Created January 3, 2015 03:21
Monadic Transducers with reduction
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DeriveFunctor #-}
module Tesser where
import Control.Monad
import Data.Bifunctor
import Data.List (foldl')
@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 / curry.hs
Created December 12, 2013 16:29 — forked from NathanHowell/curry.hs
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE StandaloneDeriving #-}