Skip to content

Instantly share code, notes, and snippets.

View mbrcknl's full-sized avatar
🕸️
catching bugs

Matthew Brecknell mbrcknl

🕸️
catching bugs
View GitHub Profile
@mbrcknl
mbrcknl / .gvimrc
Created February 27, 2013 07:55
Vim config I used for screencast http://brck.nl/hole-driven-haskell
" Disable cursor blink so I can freely cut, splice and vary the speed of the screencast.
set guicursor+=a:blinkon0
" Get rid of toolbar and scrollbars.
set guioptions-=T
set guioptions-=L
set guioptions-=r
set background=dark
@mbrcknl
mbrcknl / .profile
Created March 23, 2013 09:06
How I start gpg-agent on login to OS X. I use Macports gnupg2, with pinentry +qt4, though with a suitable adjustment to the PATH, this should work if you get your gnupg from somewhere else.
# ...
if [ -f ~/.gpg-agent-info ]; then
. ~/.gpg-agent-info
export GPG_AGENT_INFO
fi
# ...
import Data.Set.Monad as SM
import Debug.Trace as DT
(<+>) = liftM . plus
plus x y = DT.trace "." (x + y)
l = SM.fromList [0,1]
-- Intuitively expect 28 additions, but we actually get 60!
test = Set Int

Initial call

bounce(append(List(1,2,3,4,5),List(6)))

Descend into argument

append(List(1,2,3,4,5),List(6))
bounce(...)

Learning about trampolining in Scala.

I began with Ken Scambler's [YOW! Lambda Jam 2014 workshop][ws] on Free monads, but found that the simple formulation of Free derived in [exercise 1][ex1] was susceptible to stack overflow when used for trampolining in [exercise 2][ex2]. This is just an investigation into what causes this stack overflow, and how [scalaz][]'s [GoSub][] trick avoids it.

@mbrcknl
mbrcknl / Hedge.hs
Last active August 29, 2015 14:06
-- Is Set.union better than O(n+m) in some cases?
import Criterion.Main (Benchmark, bench, bgroup, defaultMain, env, whnf)
import Data.Set (Set, fromList, union)
main :: IO ()
main = defaultMain [ bgroup "union" $ map benchUnion sizes ]
-- Grow Set size exponentially, under the hypothesis that
-- Set.union will be O(log n) in this special case.
import Criterion.Main (Benchmark, bench, bgroup, defaultMain, env, whnf)
import Data.Foldable (Foldable(..),toList)
import Data.Maybe (Maybe(..))
import Data.Monoid (Monoid(..), (<>))
import Data.Set (Set,fromList)
import Prelude (Eq(..),Ord(..),Show(..),Int,(.),($),($!),Num(..),const,take,iterate,map,return,IO)
last :: Foldable t => t a -> Maybe a
last = foldl (const Just) Nothing

Difference Lists

Proposed BFPG lightning talk. 25 slides, 5 minutes, 12 seconds per slide. No problem!

September 2014

1

Motivation: we want to write something as clear as this, but this is O(n^2).

{-# LANGUAGE Rank2Types #-}
type Lens s t a b = forall f. Functor f => (a -> f b) -> (s -> f t)
type Ref s t a b = s -> Rep a b t
data Rep a b t = Rep a (b -> t)
instance Functor (Rep a b) where
fmap f (Rep a g) = Rep a (f . g)
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE ImpredicativeTypes #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
-- Richard Bird, Thinking Functionally with Haskell.
-- Chapter 2, Exercise E: