Skip to content

Instantly share code, notes, and snippets.

View puffnfresh's full-sized avatar

Brian McKenna puffnfresh

View GitHub Profile

Hi, looking for scalac flags?

This gist has been upgraded to a blog post here.

module Reverse where
open import Data.List as List hiding (reverse)
open import Data.List.Properties
open import Relation.Binary.PropositionalEquality
record ReverseLike (reverse : ∀ {A : Set} → List A → List A) : Set₁ where
constructor rl
field
reverse0 : ∀ {A} → reverse {A} [] ≡ []
@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
@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
@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
Simon Peyton-Jones
Phillip Wadler
Paul Chiusano
Tony Morris
Mark Hibberd
Edwin Brady
John Carmack
Conor McBride
Evan Czaplicki
Brian McKenna
@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 {}
@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 {
@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."
@etorreborre
etorreborre / gist:5078824
Last active March 24, 2024 14:55
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]