Skip to content

Instantly share code, notes, and snippets.

View jasonreich's full-sized avatar

Jason Reich jasonreich

View GitHub Profile
@jasonreich
jasonreich / Jigger.agda
Created December 12, 2010 19:14
A variant on Conor McBride's trick
-- Forked from http://personal.cis.strath.ac.uk/~conor/fooling/Jigger.agda
module Jigger where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
_+_ : Nat -> Nat -> Nat
zero + n = n
suc m + n = suc (m + n)
@jasonreich
jasonreich / List.hs
Created December 27, 2010 13:30
List append associativity proof in Haskell's type system... perhaps
{-
Uses the She (Stathclyde Haskell Enhancement), which you
can get from http://bit.ly/gaVM8X.
-}
{-# OPTIONS_GHC -Wall -F -pgmF she #-}
{-# LANGUAGE GADTs, KindSignatures #-}
{-# LANGUAGE TypeFamilies, TypeOperators #-}
{-# LANGUAGE RankNTypes, FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
@jasonreich
jasonreich / Monoid.hs
Created December 28, 2010 18:05
Sorta representing laws in the Haskell type system
{-
Uses the She (Stathclyde Haskell Enhancement), which you
can get from http://bit.ly/gaVM8X.
-}
{-# OPTIONS_GHC -Wall -F -pgmF she #-}
{-# LANGUAGE GADTs, KindSignatures #-}
{-# LANGUAGE TypeFamilies, TypeOperators #-}
{-# LANGUAGE RankNTypes, FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses, NoImplicitPrelude #-}
@jasonreich
jasonreich / capriagda.sh
Created January 18, 2011 23:54
Using Capri to sandbox a dev Agda installation
# Install the capri sandboxing tool.
cabal install capri
# Download Agda to a directory of your choice.
darcs get --lazy "http://code.haskell.org/Agda"
# Enter the directory. Make sure you `cabal clean` if you
# try this more than once.
cd Agda
@jasonreich
jasonreich / Makefile
Created January 25, 2011 10:25
If I spent as long writing as I did scripting the document...
INPUTS=...
default: progress.pdf
progress.pdf : progress.tex $(INPUTS) study.bib
latexmk -pdf $<
%.tex : %.markdown
pandoc -f markdown -t latex $< > $@
@jasonreich
jasonreich / ProblemC.hs
Created May 8, 2011 13:02
Candy Splitting
import Control.Arrow
import Control.Monad
-- Using ByteString a little superfluously but thought my parser might slow me down.
import qualified Data.ByteString.Lazy.Char8 as QS
import Data.Bits
import Data.List
import Data.Maybe
import Data.Word
-- | A bag of sweeties is a list of unsigned integers
@jasonreich
jasonreich / puzzle.lhs
Created November 9, 2011 12:44
Memoization of problem
Michaels solution
=================
> a 0 y = 1
> a x 0 = 1
> a x y = a (x-1) y + a x (y-1)
> result = map (\x -> a x x) [0..]
Memoised form
@jasonreich
jasonreich / Buffer.lhs
Created February 24, 2012 13:44
Buffer with Monoids
Fun with monoids
================
We'll need the monoid library.
> import Data.Monoid
Difference lists
----------------
@jasonreich
jasonreich / SmallerCheck.hs
Last active October 5, 2015 01:28
SmallerCheck – Example for ES talk
import Control.Parallel.Strategies (using, parBuffer, rseq)
import Data.List (partition)
-- *** Example Haskell functions ***
-- Is a list of integers sorted?
isOrdered :: [Int] -> Bool
isOrdered (x:y:zs) = x <= y && isOrdered (y:zs)
isOrdered _ = True
@jasonreich
jasonreich / OneDCA.hs
Last active December 12, 2015 07:49
One Dimensional CA
-- Based on http://blog.sigfpe.com/2006/12/evaluating-cellular-automata-is.html
-- But uses the Gloss (http://hackage.haskell.org/package/gloss) library to draw the image.
module OneDCA where
import Data.Bits
import Data.Word
import Graphics.Gloss
-- Universes