Skip to content

Instantly share code, notes, and snippets.

View liamoc's full-sized avatar

Liam O'Connor liamoc

View GitHub Profile
@liamoc
liamoc / gist:3176041
Created July 25, 2012 12:55
Arbitrary DFAs with a total delta function
{-# LANGUAGE GADTs, DataKinds, KindSignatures, FlexibleInstances, ScopedTypeVariables #-}
import Test.QuickCheck
import Test.QuickCheck.Gen
import Control.Applicative
import Data.List
-- Peano naturals (used on value and type level)
data Nat = Zero | Suc Nat
@liamoc
liamoc / gist:2972077
Created June 22, 2012 10:56
Implicit Parameters
data Eq a = Eq {
eq :: a -> a -> Bool,
neq :: a -> a -> Bool
}
(==) :: (?eq :: Eq a) => a -> a -> Bool
(==) = eq ?eq
(/=) :: (?eq :: Eq a) => a -> a -> Bool
(/=) = neq ?eq
@liamoc
liamoc / gist:2875241
Created June 5, 2012 14:11
Fun pointless style
import Control.Applicative
import Data.List
import qualified Data.Map as M
import Control.Arrow ((&&&), (***))
import Data.Char(isAlpha, toLower)
unscramble = curry $ fmap unwords
. uncurry mapM
. ( ( ( fmap head .)
. flip M.lookup
@liamoc
liamoc / gist:762380
Created January 2, 2011 07:30
Creating Tables in C
#include <stdio.h>
/* BEGIN HACKERY */
typedef struct field {
enum {
TABLE_NAME,
TABLE_FIELD,
TABLE_TERMINATOR
} tag;