Skip to content

Instantly share code, notes, and snippets.

data Foo = Foo { foo :: Int }
x0 = Foo { foo = 3 } -- create
x1 = x0 { foo = 4 } -- replace
x2 = foo x1 -- access
x3 = x1 { foo = foo x1 + 1 } -- apply
#!/usr/bin/perl
use strict;
use warnings;
use lib './';
use Contract;
use Contract::Predicate;
sub foo {
(require scheme/foreign)
(unsafe!)
(define strlen_t
(_fun (s) :: (s : _string) -> _int))
(define stdlib (ffi-lib #f))
(define strlen
(get-ffi-obj "strlen" stdlib strlen_t
foo1 :: Parser Foo
foo1 = do
bar <- int
baz <- int
-- This line is boring:
return Foo { bar = bar, baz = baz }
-- The coloring is wrong because Github
-- doesn't understand TH's quoted names.
foo2 :: Parser Foo
foo2 = $(doRec 'Foo
[ 'bar :- [| int |]
, 'baz :- [| int |]
])
#!/bin/sh
find ./ -name '*.dwi' \
| xargs -n1 "-d\n" egrep -l 'SINGLE:MANIAC:1[123456789]' \
| xargs -n1 "-d\n" dirname \
| xargs -n1 "-d\n" dirname \
| sort \
| uniq -c \
| sort -nk1
@ktvoelker
ktvoelker / gist:945322
Created April 27, 2011 21:59
A normal record declaration
data Foo = Foo { x :: Int, y :: Int }
@ktvoelker
ktvoelker / gist:945324
Created April 27, 2011 22:00
A record declaration with state-record
record "" [d| data Foo = Foo { x :: Int, y :: Int } |]
data IdField a b = IdField { getField :: a -> b, putField :: b -> a -> a }
@ktvoelker
ktvoelker / gist:945370
Created April 27, 2011 22:23
Getting started with state-record
git clone git://github.com/ktvoelker/state-record.git
cd state-record
cabal install