Skip to content

Instantly share code, notes, and snippets.

View puffnfresh's full-sized avatar

Brian McKenna puffnfresh

View GitHub Profile
@cnd
cnd / gist:4509874
Last active December 10, 2015 23:28
Gentoo Haskell F#
>>time ./hs 15 ~/tests/ :)
stretch tree of depth 16 check: -1
65536 trees of depth 4 check: -65536
16384 trees of depth 6 check: -16384
4096 trees of depth 8 check: -4096
1024 trees of depth 10 check: -1024
256 trees of depth 12 check: -256
64 trees of depth 14 check: -64
long lived tree of depth 15 check: -1
./hs 15 1.08s user 0.72s system 99% cpu 1.803 total
@dergachev
dergachev / GIF-Screencast-OSX.md
Last active April 28, 2025 00:02
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@etorreborre
etorreborre / gist:5078824
Last active November 16, 2024 17:40
A good summary of Scala types from http://bit.ly/XjSVKw
class Outer {
class Inner
type Type
}
trait Trait
object Object extends Outer {
val inner = new Inner
}
class OuterP[A] {
class InnerP[B]
@bodil
bodil / hindley-milner.clj
Last active August 12, 2019 18:08
Port of http://dysphoria.net/code/hindley-milner/HindleyMilner.scala to 100% pure Clojure code, complete with state monad hell. Originally based on Luca Cardelli's paper "Basic Polymorphic Typechecking" http://lucacardelli.name/Papers/BasicTypechecking.A4.pdf
;;; Clojure port of http://dysphoria.net/code/hindley-milner/HindleyMilner.scala
(ns hindley-milner
(:require [clojure.string :as str]))
(declare occurs-in? occurs-in-type?)
(defn map-state
"Evaluate a list of state monad values in sequence, producing
a list of the results of each evaluation."
@tonymorris
tonymorris / RefactoringPuzzle.scala
Created May 31, 2013 11:35
The following is an exercise in refactoring to remove code duplication. The implementation language is Scala. How would you solve it?
object RefactorPuzzle {
case class IntRdr[+A](read: Int => A) {
def map[B](f: A => B): IntRdr[B] =
IntRdr(f compose read)
def flatMap[B](f: A => IntRdr[B]): IntRdr[B] =
IntRdr(n => f(read(n)).read(n))
}
object IntRdr {
@joseanpg
joseanpg / GasterAlgebraicHierarchy97.hs
Created June 9, 2013 13:14
Gaster's Algebraic hierarchy
-- http://benedictgaster.org/wp-content/uploads/2012/08/haskwork97.pdf
-- Polymorphic Extensible Records for Haskell (page 3)
type Monoid v r = Rec { plus :: v -> v -> v , id :: v | r }
type Group v r = Monoid v { inv :: v -> v | r }
type Ring v r = Group v { mult :: v -> v -> v , one :: v | r }
iMonoid :: Monoid Int {}
Simon Peyton-Jones
Phillip Wadler
Paul Chiusano
Tony Morris
Mark Hibberd
Edwin Brady
John Carmack
Conor McBride
Evan Czaplicki
Brian McKenna
@mmhelloworld
mmhelloworld / JavaList.fr
Created June 17, 2013 06:23
Java List in Frege
module hellofrege.JavaList where
data LinkedList a = native java.util.LinkedList where
native add :: Mutable s (LinkedList a) -> a -> ST s Bool
native get :: Mutable s (LinkedList a) -> Int -> ST s (Maybe a)
native new :: () -> STMutable s (LinkedList a)
fromFregeList :: [a] -> STMutable s (LinkedList a)
fromFregeList xs = LinkedList.new () >>= loop xs where
loop (x:xs) jlist = LinkedList.add jlist x >> loop xs jlist
@luqui
luqui / codata.hs
Created July 13, 2013 21:50
Functions from codata are not necessarily codata.
import qualified Data.Searchable as S -- from infinite-search package
import Control.Applicative (liftA2)
import Data.Function (fix)
-- We will see that a function which takes codata as an argument is
-- not necessarily codata itself. Here we see an isomorphism between
-- total functions of type (Stream Bool -> a) and finite trees of the
-- shape (SBFunc a) (below), whenever a has decidable equality.
-- We will be using infinite lists as streams, pretending
@raichoo
raichoo / Vect.scala
Created October 1, 2013 16:31
Playing with dependent types in Scala
package Vect
import scala.language.higherKinds
sealed trait Nat
sealed trait Z extends Nat
sealed trait S[N <: Nat] extends Nat
trait Exists[A, +B[_ <: A]] {
type fst <: A