Skip to content

Instantly share code, notes, and snippets.

View puffnfresh's full-sized avatar

Brian McKenna puffnfresh

View GitHub Profile
@puffnfresh
puffnfresh / F.hs
Created January 30, 2014 16:12
This should fully specify reverse.
-- |
-- prop> \xs -> f (f xs) == xs
-- prop> \xs ys -> f ys ++ f xs == f (xs ++ ys)
f :: [a] -> [a]
f = foldl (flip (:)) []
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} [] ≡ []
@puffnfresh
puffnfresh / lenz-readme.md
Created February 18, 2014 01:25
Scala Lenz README

Scala Lenz

This library is a port of Haskell's lens. The goal is to provide functional lenses, isomorphisms, getters and setters.

Examples

Isomorphisms

@puffnfresh
puffnfresh / .zshrc
Created February 19, 2014 02:09
Put sandbox status in ZSH prompt
function cabal_sandbox_info() {
cabal_files=(*.cabal(N))
if [ $#cabal_files -gt 0 ]; then
if [ -f cabal.sandbox.config ]; then
echo "%{$fg[green]%}sandboxed%{$reset_color%}"
else
echo "%{$fg[red]%}not sandboxed%{$reset_color%}"
fi
fi
}
@puffnfresh
puffnfresh / Hello.scala
Created February 21, 2014 01:12
Can't make ambiguous
trait Wat[T]
object Wat {
implicit object BooleanWat extends Wat[Boolean]
}
object Hello {
implicit object AmbBooleanWat1 extends Wat[Boolean]
implicit object AmbBooleanWat2 extends Wat[Boolean]
def main(args: Array[String]) {
@puffnfresh
puffnfresh / Tagged.scala
Created March 5, 2014 21:51
Another form of unboxed tagged types.
import language.higherKinds
object Tagged {
type @@[A, B] = { type T = A }
type Id[A] = A
implicit class Taggable[A](a: A) {
def tagged[B]: A @@ B = a.asInstanceOf[A @@ B]
}
plusOne :: (Int -> Int) -> (Int -> Int)
plusOne = (. (+1))
timesTwo :: (Int -> Int) -> (Int -> Int)
timesTwo = (. (*2))
infixl 8 &
(&) :: a -> ((a -> a) -> (a -> a)) -> a
(&) = flip ($ id)
import scalaz.{PLens, @?>}
// Ah, breaks the prism laws!
// > val two = within(_ == 2, PLens.plensId)
// > two.set(2, 3).flatMap(two.get)
// None
def within[A, B](f: A => Boolean, p: A @?> B): A @?> B = PLens.plens { (a: A) =>
if (f(a))
object Main extends SafeApp {
def handleEvent(i: Int) =
Task.delay {
Task.fork(Task.delay {
println(i)
Thread.sleep(1000)
}).runAsync(_ => ())
}
override def run(args: ImmutableArray[String]) = IO {
@puffnfresh
puffnfresh / NoDynamics.scala
Created March 25, 2014 19:54
You won't be able to compile this.
// You won't be able to compile this with:
// scala -language:dynamics NoDynamics.scala
// These two ambiguous implicits disable the `dynamics` feature.
implicit def ambDynamics1: language.dynamics.type = ???
implicit def ambDynamics2: language.dynamics.type = ???
object Woo extends Dynamic {
def selectDynamic(name: String) = s"$name a mess of a language"