Skip to content

Instantly share code, notes, and snippets.

@runarorama
runarorama / gist:87a53916f82c39ce4305
Last active October 4, 2015 20:20
Icelandic place names if they were in Britain
Reykjavík - Reekswich
Þingvellir - Thingweald
Akureyri - Ackerearth
Mývatn - Midgewater
Skaftafell - Shaftfell
Ísafjörður - Icefirth
Vík í Mýrdal - Wick in Miredale
Jökulsárlón - Icemere Loch
Keflavík - Caeflwick
Heimaey - Hamey
Kvæðasafn - Snorri Hjartarson - 0.752743
The Feynman Lectures on Physics Vol 1 - Richard Feynman - 0.693827
How We Know - Harry Binswanger - 0.66043
The Knowing Animal: A Philosophical Inquiry Into Knowledge and Truth - Raymond Tallis - 0.646221
Dancing with the Muses: A Historical Approach to Basic Concepts of Music - M. Zachary Johnson - 0.646221
A Mathematical Challenge: The 3x+1 Problem - Jeffrey C. Lagarias - 0.646221
The Hand: A Philosophical Inquiry Into Human Being - Raymond Tallis - 0.646221
Parallel and Concurrent Programming in Haskell: Techniques for Multicore and Multithreaded Programming - Simon Marlow - 0.634218
Volition As Cognitive Self Regulation - Harry Binswanger - 0.62231
Harry Potter and the Sorcerer's Stone (Harry Potter #1) - J.K. Rowling - 0.596954
@runarorama
runarorama / gist:dba2699f064460228315
Last active June 4, 2017 16:28
Finalizers with monadic regions
object SafeIO {
trait Brace[M[_]] extends Monad[M] {
def brace[A,B,C](acquire: M[A])(release: A => M[B], go: A => M[C]): M[C]
def snag[A](m: M[A], f: Throwable => M[A]): M[A]
def lift[A](t: Task[A]): M[A]
}
object Brace {
def apply[M[_]:Brace]: Brace[M] = implicitly[Brace[M]]
@runarorama
runarorama / gist:1bf207402a53be986242
Created May 13, 2015 00:01
Initial sketch of ermine typer
module Infer where
import Control.Monad.State
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
data Var = V {-# UNPACK #-} !Int (Maybe String)
data HM = HM
{ nextVar :: {-# UNPACK #-} !Int
@runarorama
runarorama / gist:33986541f0f1ddf4a3c7
Created May 7, 2015 14:06
Higher-kinded types encoded as path-dependent types
trait λ {
type α
}
trait Functor extends λ {
type α <: λ
def map[A,B](x: α { type α = A })(f: A => B): α { type α = B }
}
@runarorama
runarorama / gist:5af95832695e02426d32
Created May 4, 2015 20:51
Superstitious parent mode
import java.util.concurrent._
/**
* A thread pool for superstitious parent threads who
* know they shouldn't let their child threads back in the pool after
* eating, without waiting at least `crampFactor` milliseconds.
*/
object Superstitious {
def pool(crampFactor: Long) = new ThreadPoolExecutor(
0, Int.MaxValue, 60L, TimeUnit.SECONDS, new SynchronousQueue[Runnable]) {
@runarorama
runarorama / gist:a98da9dafd0e2032ea58
Last active August 29, 2015 14:20
Names for extensible protocol language
Tenor
Tonic
Bouncy
Ermis
Yak
Samtal
Lithe
Plastic
Bendy
BendyBus
/**
* Free applicative functors
*/
sealed trait FreeA[F[_],A] {
/**
* The canonical monoidal natural transformation that interprets
* this free program by giving it the semantics of the applicative functor `G`.
*/
def foldMap[G[_]:Applicative](f: F ~> G): G[A] = this match {
case Pure(x) => Applicative[G].pure(x)
class Group a where
gempty :: a
gappend :: a -> a -> a
ginv :: a -> a
data FreeGroup a = FreeGroup { outFreeGroup :: forall m. Group m => (a -> m) -> m }
nil :: FreeGroup a
nil = FreeGroup (\_ -> gempty)
import scala.reflect.macros.Context
import scala.language.experimental.macros
import scala.annotation.StaticAnnotation
object helloMacro {
def impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
import c.universe._
import Flag._
val args = c.prefix.tree match {
case q"new $name($m)" => c.eval(c.Expr[Map[String, String]](c.resetAllAttrs(m)))