diff --git a/AUTHORS b/AUTHORS
deleted file mode 100644
--- a/AUTHORS
+++ /dev/null
@@ -1,1 +0,0 @@
-leon at melding-monads dot com
diff --git a/Control/Monad/Queue/Allison.hs b/Control/Monad/Queue/Allison.hs
--- a/Control/Monad/Queue/Allison.hs
+++ b/Control/Monad/Queue/Allison.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE RankNTypes #-}
+{-# LANGUAGE RankNTypes, CPP #-}
 
 -----------------------------------------------------------------------------
 -- |
@@ -55,7 +55,9 @@
   f <*> v   = Q (\k -> unQ f (\g -> unQ v (k . g)))
 
 instance Monad (Q e) where
-  return a  = Q (\k -> k a)
+#if !(MIN_VERSION_base(4,8,0))
+  return = pure
+#endif
   m >>= f   = Q (\k -> unQ m (\a -> unQ (f a) k))
 
 callCC :: ((a -> forall b. Q e b) -> Q e a) -> Q e a
diff --git a/Control/Monad/Queue/Corec.hs b/Control/Monad/Queue/Corec.hs
--- a/Control/Monad/Queue/Corec.hs
+++ b/Control/Monad/Queue/Corec.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE RankNTypes #-}
+{-# LANGUAGE RankNTypes, CPP #-}
 
 -----------------------------------------------------------------------------
 -- |
@@ -52,7 +52,9 @@
   f <*> v   = Q (\k -> unQ f (\g -> unQ v (k . g)))
 
 instance Monad (Q w e) where
-  return a  = Q (\k -> k a)
+#if !(MIN_VERSION_base(4,8,0))
+  return = pure
+#endif
   m >>= f   = Q (\k -> unQ m (\a -> unQ (f a) k))
 
 callCC :: ((a -> forall b. Q w e b) -> Q w e a) -> Q w e a
diff --git a/Control/Monad/Queue/ST.hs b/Control/Monad/Queue/ST.hs
deleted file mode 100644
--- a/Control/Monad/Queue/ST.hs
+++ /dev/null
@@ -1,61 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Control.Monad.Queue.ST
--- Copyright   :  (c) Leon P Smith 2009
--- License     :  BSD3
---
--- Maintainer  :  leon at melding-monads dot com
--- Stability   :  experimental
--- Portability :  portable
---
------------------------------------------------------------------------------
-
-{-# LANGUAGE RankNTypes #-}
-
-module Control.Monad.Queue.ST
-     ( Q()
-     , enQ
-     , deQ
-     , lenQ_
-     , runResult
-     ) where
-
-import qualified Control.Monad.Queue.Class
-import Control.Monad.Queue.Util
-import Control.Monad.ST.Strict
-import Data.STRef.Strict
-
-type  ListPtr st a = STRef st (List st a)
-data  List st a
-   =  Null
-   |  Cons a {-# UNPACK #-} !(ListPtr st a)
-
-type  QSt st res elt = LenType -> ListPtr st elt -> ListPtr st elt -> ST st res
-newtype Q elt a
-      = Q { unQ :: forall res st. ((a -> QSt st res elt) -> QSt st res elt) }
-
-instance Monad (Q st) where
-    return a = Q (\k -> k a)
-    m >>= f  = Q (\k -> unQ m (\a -> unQ (f a) k))
-
-enQ :: e -> Q e ()
-enQ e  = Q $ \k n a z -> do
-                 z' <- newSTRef Null
-                 writeSTRef z (Cons e z')
-                 (k () $! n+1) a z'
-
-deQ :: Q e (Maybe e)
-deQ    = Q $ \k n a z -> do
-                 list <- readSTRef a
-                 case list of
-                   Null
-                     -> (k Nothing  $! n-1) a  z
-                   (Cons e a')
-                     -> (k (Just e) $! n-1) a' z
-
-lenQ_ :: Q e LenType
-lenQ_ = Q (\k n a z -> k n n a z)
-
-runResult m = runST $ do
-  ref <- newSTRef Null
-  unQ m (\a n front back -> return a) 0 ref ref
diff --git a/Data/Queue/Class.hs b/Data/Queue/Class.hs
deleted file mode 100644
--- a/Data/Queue/Class.hs
+++ /dev/null
@@ -1,21 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Data.Queue.Class
--- Copyright   :  (c) Leon P Smith 2009
--- License     :  BSD3
---
--- Maintainer  :  leon at melding-monads dot com
--- Stability   :  experimental
--- Portability :  portable
---
------------------------------------------------------------------------------
-
-
-module Data.Queue.Class
-     ( Queue(empty, enque, deque)
-     ) where
-
-class Queue q where
-   empty :: q a
-   enque :: a   -> q a -> q a
-   deque :: q a -> (Maybe a, q a)
diff --git a/Data/Queue/Okasaki.hs b/Data/Queue/Okasaki.hs
deleted file mode 100644
--- a/Data/Queue/Okasaki.hs
+++ /dev/null
@@ -1,94 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Data.Queue.Okasaki
--- Copyright   :  (c) The University of Glasgow 2002
--- License     :  BSD-style (see the file libraries/base/LICENSE)
---
--- Maintainer  :  leon at melding-monads dot com
--- Stability   :  experimental
--- Portability :  portable
---
--- Queues with constant time operations, from
--- /Simple and efficient purely functional queues and deques/,
--- by Chris Okasaki, /JFP/ 5(4):583-592, October 1995.
---
--- Based on the incremental reversals of lazy lists.
---
------------------------------------------------------------------------------
-
-module  Data.Queue.Okasaki
-     (  Q
-        -- * Primitive operations
-        -- | Each of these requires /O(1)/ time in the worst case.
-     ,  empty, enque, deque
-        -- * Queues and lists
-     ,  listToQueue, queueToList
-     )  where
-
-import Prelude -- necessary to get dependencies right
-import qualified Data.Queue.Class as Class
-
--- import Data.Typeable
-
--- | The type of FIFO queues.
-data Q a = Q [a] [a] [a]
-
-
--- #include "Typeable.h"
--- `INSTANCE_TYPEABLE1(Queue,queueTc,"Queue")
-
--- Invariants for Q xs ys xs':
---	length xs = length ys + length xs'
---	xs' = drop (length ys) xs	-- in fact, shared (except after fmap)
--- The queue then represents the list xs ++ reverse ys
-
-
-instance Functor Q where
-	fmap f (Q xs ys xs') = Q (map f xs) (map f ys) (map f xs')
-	-- The new xs' does not share the tail of the new xs, but it does
-	-- share the tail of the old xs, so it still forces the rotations.
-	-- Note that elements of xs' are ignored.
-
--- | The empty queue.
-empty :: Q a
-empty = Q [] [] []
-
--- | Add an element to the back of a queue.
-enque :: a -> Q a  -> Q a
-enque y (Q xs ys xs') = makeQ xs (y:ys) xs'
-
--- | Attempt to extract the front element from a queue.
--- If the queue is empty,  return 'Nothing' paired with the original queue
--- otherwise return 'Just' the first element paired with the modified queue
-
-deque :: Q a -> (Maybe a, Q a)
-deque q@(Q [] _ _) = (Nothing,  q)
-deque q@(Q (x:xs) ys xs') = (Just x, makeQ xs ys xs')
-
--- Assuming
---	length ys <= length xs + 1
---	xs' = drop (length ys - 1) xs
--- construct a queue respecting the invariant.
-makeQ :: [a] -> [a] -> [a] -> Q a
-makeQ xs ys [] = listToQueue (rotate xs ys [])
-makeQ xs ys (_:xs') = Q xs ys xs'
-
--- Assuming length ys = length xs + 1,
---	rotate xs ys zs = xs ++ reverse ys ++ zs
-rotate :: [a] -> [a] -> [a] -> [a]
-rotate [] (y:_) zs = y : zs		-- the _ here must be []
-rotate (x:xs) (y:ys) zs = x : rotate xs ys (y:zs)
-
--- | A queue with the same elements as the list.
-listToQueue :: [a] -> Q a
-listToQueue xs = Q xs [] xs
-
--- | The elements of a queue, front first.
-queueToList :: Q a -> [a]
-queueToList (Q xs ys _) = xs ++ reverse ys
-
-
-instance Class.Queue Q where
-   empty = empty
-   deque = deque
-   enque = enque
diff --git a/Data/Queue/TwoStack.hs b/Data/Queue/TwoStack.hs
deleted file mode 100644
--- a/Data/Queue/TwoStack.hs
+++ /dev/null
@@ -1,93 +0,0 @@
------------------------------------------------------------------------------
--- |
--- Module      :  Data.Queue.TwoStack
--- Copyright   :  (c) Leon P Smith 2009
--- License     :  BSD3
---
--- Maintainer  :  leon at melding-monads dot com
--- Stability   :  experimental
--- Portability :  portable
---
--- Two-Stack Queues of functional programming folklore.
--- Notably mentioned inside Chris Okasaki's thesis, with
--- relevant citations.
---
--- /Purely Functional Data Structures/ by Chris Okasaki,
--- /Cambridge University Press/,  1998
---
--- http://www.cs.cmu.edu/~rwh/theses/okasaki.pdf
---
------------------------------------------------------------------------------
-
-module Data.Queue.TwoStack
-     ( Q()
-     , empty
-     , enque
-     , deque
-     , listToQueue
-     , queueToList
-     , len
-     ) where
-
-import qualified Data.Queue.Class as Class
-import Data.List
-
-import Control.Monad.Queue.Util
-
-data Q e = Q !LenType [e] [e]
-
-instance Functor Q where
-  fmap f (Q n as zs) = Q n (map f as ++ map f (reverse zs)) []
-
-instance (Eq e) => Eq (Q e) where
-  (Q ln as ys) == (Q mn bs zs)   =  ln == mn  &&  loop   as bs ys zs
-    where
-      loop as bs (y:ys) (z:zs)   =  y == z    &&  loop   as bs ys zs
-      loop as bs ys     zs       =                loop2  as bs ys zs
-
-      loop2 (a:as) (b:bs) ys zs  =  a == b    &&  loop2  as bs ys zs
-      loop2 as     []     [] zs  =  as == reverse zs
-      loop2 []     bs     ys []  =  bs == reverse ys
-
-instance (Ord e) => Ord (Q e) where
-  compare (Q _ as ys) (Q _ bs zs) = loop as bs ys zs
-     where
-       loop (a:as) (b:bs) ys zs
-          = case compare a b of
-             LT -> LT
-             EQ -> loop as bs ys zs
-             GT -> GT
-       loop [] [] [] [] = EQ
-       loop [] bs [] zs = LT
-       loop [] bs ys zs = loop (reverse ys) bs [] zs
-       loop as [] ys [] = GT
-       loop as [] ys zs = loop as (reverse zs) ys []
-
-empty :: Q e
-empty =  Q 0 [] []
-
-enque :: e -> Q e -> Q e
-enque z  (Q 0 []     [])  = Q 1     [z]     []
-enque z  (Q n (a:as) zs)  = Q (n+1) (a:as)  (z:zs)
-
-deque :: Q e -> (Maybe e, Q e)
-deque    (Q 0 []     [])  =   ( Nothing  ,  Q 0     []   []  )
-deque    (Q n (a:as) zs)
-         |  null as       =   ( Just a   ,  Q (n-1) as'  []  )
-         |  otherwise     =   ( Just a   ,  Q (n-1) as   zs  )
-            where as'     = reverse zs
-
-listToQueue :: [e] -> Q e
-listToQueue as = Q (genericLength as) as []
-
-queueToList :: Q e -> [e]
-queueToList (Q _ as zs) = as ++ reverse zs
-
-len :: Q e -> LenType
-len (Q l _ _) = l
-
-
-instance Class.Queue Q where
-  empty = empty
-  enque = enque
-  deque = deque
diff --git a/README b/README
deleted file mode 100644
--- a/README
+++ /dev/null
@@ -1,3 +0,0 @@
-To compile the timing program,  change to the tests/ directory, and then run
-
-ghc --make -O2 Time.hs -i..
diff --git a/control-monad-queue.cabal b/control-monad-queue.cabal
--- a/control-monad-queue.cabal
+++ b/control-monad-queue.cabal
@@ -1,5 +1,5 @@
 Name:                control-monad-queue
-Version:             0.2
+Version:             0.2.0.1
 Description:
   This library provides efficient real-time queues via self-referential
   lazy lists.  The technique was first published in
@@ -35,9 +35,9 @@
 
 source-repository head
   type:      darcs
-  location:  http://patch-tag.com/r/lpsmith/control-monad-queue/pullrepo
+  location:  http://hub.darcs.net/lpsmith/control-monad-queue
 
 source-repository this
   type:      darcs
-  location:  http://patch-tag.com/r/lpsmith/control-monad-queue/pullrepo
-  tag:       0.2
+  location:  http://hub.darcs.net/lpsmith/control-monad-queue
+  tag:       0.2.0.1
diff --git a/doc/CorecQueues.bib b/doc/CorecQueues.bib
deleted file mode 100644
--- a/doc/CorecQueues.bib
+++ /dev/null
@@ -1,184 +0,0 @@
-@Article{biernacki06,
-  author  = {Dariusz Biernacki and Olivier Danvy and {Chung-chieh} Shan},
-  title   = {On the Static and Dynamic Extents of Delimited Continuations},
-  journal = {Science of Computer Programming},
-  year    = {2006},
-  volume  = {60},
-  number  = {3},
-  pages   = {274--297},
-  url     = {http://www.brics.dk/RS/05/36/}
-}
-
-
-@Article{Bird84,
-  author  = {Richard S. Bird},
-  title   = {Using circular programs to eliminate multiple traversals of data},
-  journal = {Acta Informatica},
-  year    = {1984},
-  volume  = {21},
-  number  = {3},
-  month   = {Oct},
-  pages   = {239--250}
-}
-
-@Article{allison89,
-  author  = {Lloyd Allison},
-  title   = {Circular Programs and Self-Referential Structures},
-  journal = {Software Practice and Experience},
-  volume  = {19},
-  number  = {2},
-  month   = {Feb},
-  year    = {1989},
-  url     = {http://www.csse.monash.edu.au/~lloyd/tildeFP/1989SPE/}
-}
-
-
-@inproceedings{wadler89,
- author       = {Philip Wadler},
- title        = {Theorems for free!},
- booktitle    = {FPCA '89: Proceedings of the fourth international conference on functional programming languages and computer architecture},
- year         = {1989},
- isbn         = {0-89791-328-0},
- pages        = {347--359},
- location     = {Imperial College, London, United Kingdom},
- doi          = {http://doi.acm.org/10.1145/99370.99404},
- publisher    = {ACM},
- address      = {New York, NY, USA},
- url          = {http://homepages.inf.ed.ac.uk/wadler/topics/parametricity.html}
- }
-
-@Article{friedman87,
-  author    = "Daniel P Friedman and David S Wise",
-  title     = "Cons should not evaluate it's arguments",
-  journal   = "Automata, Languages, and Programming",
-  publisher = "Edinburgh University Press",
-  pages     = "257--284",
-  year      = 1976,
-  url       = {http://www.cs.indiana.edu/cgi-bin/techreports/TRNNN.cgi?trnum=TR44},
-}
-
-@PhdThesis{santos95,
-  author = {Andr\'{e} L. M. Santos},
-  title  = {Compilation by transfomation in non-strict functional languages},
-  school = {University of Glasgow},
-  month  = {Jul},
-  year   = {1995},
-  url    = {http://www.di.ufpe.br/~alms/ps/thesis.ps.gz},
-}
-
-
-@Article{okasaki95,
-  author  = {Chris Okasaki},
-  title   = {Simple and Efficient Purely Functional Queues and Deques},
-  journal = {Journal of Functional Programming},
-  volume  = {5},
-  number  = {4},
-  pages   = {583--592},
-  month   = {Oct},
-  year    = {1995},
-  url     = {http://www.eecs.usma.edu/webs/people/okasaki/pubs.html#jfp95},
-}
-
-@Book{okasaki98,
-  author    = {Chris Okasaki},
-  title     = {Purely Functional Data Structures},
-  publisher = {Cambridge University Press},
-  year      = {1998},
-  url       = {http://www.eecs.usma.edu/webs/people/okasaki/pubs.html#cup98},
-}
-
-@misc{gill99,
-  author = {Andy Gill et al},
-  title  = {The Monad Template Library},
-  url    = {http://hackage.haskell.org/package/mtl},
-}
-
-@misc{smith-hackage09,
-  author = {Leon P Smith},
-  title  = {control-monad-queue},
-  url    = {http://hackage.haskell.org/package/control-monad-queue},
-}
-
-@Book{eopl,
-  author    = {Daniel P Friedman and Mitchell Wand and Christopher T Haynes},
-  title     = {Essentials of Programming Languages},
-  edition   = {2},
-  publisher = {MIT Press},
-  year      = {2001},
-}
-
-@phdthesis{erkok02,
-  author    = {Levent Erk\"{o}k},
-  title     = {Value Recursion in Monadic Computations},
-  school    = {OGI School of Engineering, OHSU},
-  address   = {Portland, Oregon},
-  year      = {2002},
-  url       = {http://leventerkok.googlepages.com/erkok-thesis.pdf},
-}
-
-@Book{haskellroad,
-  author    = {Kees Doets and Jan van Eijck},
-  title     = {The Haskell Road to Logic, Maths, and Programming},
-  publisher = {King's College Publications},
-  year      = {2004},
-}
-
-@Article{bgj04,
-  author    = {Clem {Baker-Finch} and Kevin Glynn and Simon {Peyton-Jones}},
-  title     = {Constructed Product Result Analysis for Haskell},
-  journal   = {Journal of Functional Programming},
-  volume    = {14},
-  number    = {2},
-  pages     = {211-245},
-  month     = {Mar},
-  year      = {2004},
-  url       = {http://research.microsoft.com/en-us/um/people/simonpj/Papers/cpr/},
-}
-
-@Article{swierstra05,
-  author    = {Wouter Swietstra},
-  title     = {Why Attribute Grammars Matter},
-  journal   = {The Monad Reader},
-  volume    = {4},
-  month     = {Jul},
-  year      = {2005},
-  url       = {http://www.haskell.org/sitewiki/images/8/85/TMR-Issue13.pdf},
-}
-
-
-@Article{hinze06,
-  author    = {Ralf Hinze and Ross Paterson},
-  title     = {Finger trees: a simple general-purpose data structure},
-  journal   = {Journal of Functional Programming},
-  volume    = {16},
-  number    = {2},
-  pages     = {197--217},
-  year      = {2006},
-  url       = {http://www.soi.city.ac.uk/~ross/papers/FingerTree.pdf},
-}
-
-@inproceedings{okasaki00,
- author = {Chris Okasaki},
- title = {Breadth-first numbering: lessons from a small exercise in algorithm design},
- booktitle = {ICFP '00: Proceedings of the fifth ACM SIGPLAN international conference on Functional programming},
- year = {2000},
- isbn = {1-58113-202-6},
- pages = {131--136},
- doi = {http://doi.acm.org/10.1145/351240.351253},
- publisher = {ACM},
- address = {New York, NY, USA},
- url = {http://www.eecs.usma.edu/webs/people/okasaki/pubs.html#icfp00},
- }
-
-@techreport{jones93,
-    author = {Geraint Jones and Jeremy Gibbons},
-    title = {Linear-time breadth-first tree algorithms: An exercise in the arithmetic of folds and zips},
-    institution = {Dept of Computer Science, University of Auckland},
-    year = {1993},
-    url = {http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.45.4052},
-}
-
-@misc{smith2010,
-Author = {Leon P Smith},
-Title = {Writer Monads via Continuations},
-howpublished = {\url{http://blog.melding-monads.com/2010/03/14/writer-monads-via-continuations/}} }
diff --git a/doc/CorecQueues.lhs b/doc/CorecQueues.lhs
deleted file mode 100644
--- a/doc/CorecQueues.lhs
+++ /dev/null
@@ -1,1134 +0,0 @@
-\documentclass[tikz]{tmr}
-
-%include lhs2TeX.fmt
-%format . = "."
-%if style == poly
-%format bot = "\bot"
-%format forall = "\forall"
-%endif
-%options ghci -pgmL lhs2TeX -optL--pre
-
-
-\title{Lloyd Allison's Corecursive Queues:\\Why Continuations Matter}
-\author{Leon P Smith\email{leon@@melding-monads.com}}
-\date{July 29, 2009}
-
-\newcommand{\hiddencode}[1]{}
-\newcommand{\superscript}[1]{\ensuremath{^{\textrm{#1}}}}
-\newcommand{\nth}{n\superscript{th}\ }
-
-\hiddencode{
-\begin{code}
-{-# LANGUAGE MultiParamTypeClasses       #-}
-{-# LANGUAGE FunctionalDependencies      #-}
-{-# LANGUAGE FlexibleInstances           #-}
-{-# LANGUAGE FlexibleContexts            #-}
-{-# LANGUAGE RankNTypes                  #-}
-
-{-# LANGUAGE NoMonomorphismRestriction   #-}
-{-# LANGUAGE GeneralizedNewtypeDeriving  #-}
-
-{-# LANGUAGE BangPatterns  #-}
-{-# LANGUAGE RecursiveDo   #-}
-
-module Paper where
-import Control.Monad.Cont                 -- The Monad Template Library
-import Control.Monad.Reader
-import Control.Monad.Writer
-import Control.Monad.State
-
-import Control.Monad.ST.Strict
-import Data.STRef.Strict
-
-import Control.Monad(mapM_, liftM)        -- A few basic library functions
-import Control.Arrow((***), (&&&), (>>>))
-import Data.List(zipWith3)
-import Data.Function(fix)
-import Data.Ratio
-
-import Data.IORef                         -- For the thought experiment
-import System.IO.Unsafe
-import qualified Debug.Trace
-
-import GHC.Exts -- (inline)
-
-trace   = Debug.Trace.trace
-
-
-toTikzString maxdepth branch leaf t = "  \\" ++ loop 0 t ";\n"
-  where
-    loop n t str
-      | n < maxdepth
-      = case t of
-         (Leaf a) -> "node {" ++ leaf a ++ "}" ++ str
-         (Branch b l r) -> "node {" ++ branch b ++ "}\n"
-                        ++ replicate (7*n+3) ' ' ++ "child {"
-                        ++ loop (n+1) l ("}\n" ++ replicate (7*n+3) ' '
-                                         ++ "child {" ++ (loop (n+1) r ("}" ++ str)))
-      | otherwise
-      = case t of
-          (Leaf a) -> "node {" ++ leaf a ++ "}" ++ str
-          (Branch b _l _r) -> "node {" ++ branch b ++ "} child {} child {}" ++ str
-
-toFrac x = "$\\frac{" ++ show (numerator x) ++ "}{" ++ show (denominator x) ++ "}$"
-
-\end{code}
-}
-
-\begin{document}
-\section{Abstract}
-
-In a purely functional setting,  real-time queues are traditionally thought to be much harder to implement than either real-time stacks or amortized $\mathcal O(1)$ queues.  In ``Circular Programs and Self-Referential Structures,''~\cite{allison89}  Lloyd Allison uses \emph{corecursion} and \emph{self-reference} to implement a queue by defining a lazy list in terms of itself.   This provides a simple,  efficient, and attractive implementation of real-time queues.
-
-While Allison's queue is general, in the sense it is straightforward to adapt  his technique to a new algorithm,  a problem has been the lack of a reusable library implementation.   This paper solves this problem by structuring the corecursion using a monadic interface and continuations.
-
-Because Allison's queue is not fully persistent,  it cannot be a first class value.   Rather,  it is encoded inside particular algorithms written in an extended continuation passing style.   In direct style, this extension corresponds to  |mapCont|,  a control operator found in |Control.Monad.Cont|, part of the Monad Template Library for Haskell.~\cite{gill99}  This paper argues that |mapCont| cannot be expressed in terms of |callCC|,  |return|,  and |(>>=)|.
-
-The essence of this paper is |mfixish|, a novel fixpoint operator for continuations.  It cooperates with |mapCont| to create value recursion.   Although this paper tends to avoid explicit use of |mfixish|,  it can be used to introduce the self-reference inherent in corecursive queues.
-
-\section{Introduction}
-
-Richard Bird is well known for popularizing ``circular programming,''~\cite{bird84} which in modern terminology is included under the term ``corecursion.''~\cite{haskellroad}   One of the best known examples defines an infinite list of Fibonacci numbers.  However, as this paper is about queues,  our running example is breadth-first traversals of binary trees.   Thus, for our first example in Figure~\ref{fibtrees}, we corecursively define the Fibonacci trees instead.
-
-\begin{listing}
-\begin{code}
-data  Tree a b
-   =  Leaf    a
-   |  Branch  b (Tree a b) (Tree a b)
-      deriving (Eq,Show)
-
-labelDisj :: (a -> c) -> (b -> c) -> Tree a b -> c
-labelDisj leaf branch (Leaf    a      ) = leaf    a
-labelDisj leaf branch (Branch  b _ _  ) = branch  b
-
-childrenOf :: Tree a b ->  [Tree a b]
-childrenOf (Leaf    _      )  =   []
-childrenOf (Branch  _ l r  )  =   [l,r]
-\end{code}
-\caption{Binary Trees and useful helper functions}
-\label{binarytrees}
-\end{listing}
-
-\begin{figure}
-\begin{code}
-fib :: Int -> Tree Int Int
-fib n = fibs !! (n-1)
-  where
-    fibs = Leaf 0 : Leaf 0 : zipWith3 Branch [1..] fibs (tail fibs)
-\end{code}
-\centering
-\include{fibtrees}
-\caption{Fibonacci Trees}
-\label{fibtrees}
-\end{figure}
-
-\begin{figure}
-\begin{code}
-sternBrocot :: Tree a (Ratio Integer)
-sternBrocot = loop 0 1 1 0
-   where loop a b x y
-          = Branch (m%n) (loop a b m n) (loop m n x y)
-            where  m  = a + x
-                   n  = b + y
-\end{code}
-\centering
-\include{sternbrocot}
-\caption{The Stern-Brocot Tree}
-\label{sternbrocot}
-\end{figure}
-
-The indexing was chosen so that the number of leaves in the \nth Fibonacci tree is equal to the \nth Fibonacci number.  The branches are labeled with the the depth of the tree.  This definition uses self-reference and sharing to efficiently represent each additional tree with a constant amount of extra space.   Of course, fully traversing such a tree would take an exponential amount of time.
-
-The second example defines  the Stern-Brocot tree, shown in Figure~\ref{sternbrocot}.   Despite that this definition does not employ self reference,  this is a corecursive definition because it is infinite and thus requires lazy evaluation. The Stern-Brocot tree is interesting because every positive rational number is generated in reduced form at exactly one branch.   Not only does this prove that the rationals are countable,  it can be computed more efficiently than the standard Cantor diagonalization.
-
-These examples were chosen such that any two subtrees in this family are equal if and only if their labels are equal.  This is true even for the Fibonacci trees:  even though labels are repeated,  the subtrees are still equal.  This property can be exploited to efficiently and accurately test whether two breadth-first traversals might be equivalent.
-
-Having separate types for the labels of branches and leaves enables one to better exploit Haskell's type system.   An example is the polymorphic leaf type for |sternBrocot|.  Along the lines of Philip Wadler's classic paper ``Theorems for Free'',~\cite{wadler89} this almost proves that the Stern-Brocot tree is both complete and infinite,  in the sense that every counterexample to this line of reasoning involves \emph{partial data}.  Common examples of partial data are \emph{infinite nonproductive loops} and the use of Haskell's |error| function,  such as this definition of |bot|:
-
-\begin{code}
-bot :: forall a . a
-bot = error "bottom"
-\end{code}
-
-However,  not every corecursive definition produces a conceptually infinite data structure.  Lloyd Allison's queue is a good example:  it is self-referential, and thus depends on lazy evaluation.   Allison's queues can and often do produce a finite object.
-
-A simple breadth-first traversal using Allison's queue is given along with a sample execution in Figure~\ref{levelOrder}.  The execution abuses notation slightly,  as necessary for readability:   the elements of the queue are trees, not labels.   However,  as the labels are unique for the examples given,  this does not lead to ambiguity.
-
-A corecursive queue is represented by a single lazy list.   The end of the queue is represented by a thunk, which can produce the next element on demand.  This thunk contains a pointer back to the first element in the queue and the number of elements currently in the queue.   When an element is enqueued,  call-by-need evaluation \emph{implicitly mutates} the end of the list.
-
-The Fibonacci example uses a lazy list sort of like a queue.   New elements are ``enqueued'' when they are produced by |zipWith|,  which occurs in sync with elements being ``dequeued'' when they are consumed by pattern matching inside |zipWith|.
-
-Of course,  most queue-based algorithms don't have this level of synchronization.   During a level-order traversal of a Fibonacci tree,   the queue will grow and shrink frequently.  We must be careful not to run off the end of the queue and pattern match against elements that aren't there.  The easiest approach is to track the number of elements in the queue.
-
-\begin{figure}[t]
-\begin{code}
-levelOrder ::  Tree a b  ->  [Tree a b]
-levelOrder     tree      =   queue
-  where
-    queue = tree : explore 1 queue
-
-    explore ::  Int ->   [ Tree a b ]               ->  [ Tree a b ]
-    explore     0                            q      =            []
-    explore     (n+1)    ( Branch  _ l r  :  q'  )  =   l : r :  explore (  n+2)  q'
-    explore     (n+1)    ( Leaf    _      :  q'  )  =            explore    n     q'
-\end{code}
-\centering
-\include{levelorder}
-\caption{A Corecursive Queue, and a trace of |levelOrder (fib 5)|}
-\label{levelOrder}
-\end{figure}
-
-Pattern matching creates demand for computation,  thus pattern matching on the empty queue causes this thunk to reenter itself, creating an infinite nonproductive loop.   In effect,  in order to compute the answer, the answer must have already been computed.   Explicitly tracking length breaks this cycle.   By knowing via other means that the queue is empty,  we can avoid pattern matching and continue or terminate the queue as needed,  as illustrated in the last step of the sample execution.
-
-Note that the type of the counter is explicitly given.  Otherwise,  Haskell would typically default to arbitrary precision integers.    On GHC, this leads to a noticable, though modest, slowdown and increase in memory allocation in certain micro-benchmarks, such as a complete traversal of a Fibonacci trees.
-
-\begin{listing}
-\begin{code}
-isBranch = labelDisj (const False) (const True)
-
-levelOrder' ::  Tree a b  ->  [Tree a b]
-levelOrder'     tree      =   queue
-  where
-    queue  | isBranch tree   = tree :  explore 1 queue
-           | otherwise       =         explore 0 queue
-
-    explore :: Int -> [Tree a b] -> [Tree a b]
-    explore      0       _
-      =  []
-    explore   (  n+1) (  Branch _ l r : q')
-      =  if (isBranch  l)
-         then   if (isBranch r)
-                then   l :  r :  explore  (  n+2)  q'
-                else   l :       explore  (  n+1)  q'
-         else   if (isBranch r)
-                then        r :  explore  (  n+1)  q'
-                else             explore     n     q'
-\end{code}
-\caption{Avoiding leaves}
-\label{allison-code}
-\end{listing}
-
-If one doesn't care about leaves or their contents,  one might prefer a variant of |levelOrder| that does not enqueue the leaves.  Listing~\ref{allison-code} presents Lloyd Allison's original code,  translated from Lazy ML to Haskell.  It contains repeated code in the inner conditional branches.   This approach is not unreasonable in this specific case,  however, it does not scale.  The easiest way to eliminate the redundant branch is introduce a helper function that processes a list of trees to possibly enqueue.
-
-\begin{listing}
-\begin{code}
-levelOrder'2 ::  Tree a b  ->  [  Tree a b  ]
-levelOrder'2     tree      =      queue
-  where
-     queue = enqs [tree] 0 queue
-
-     enqs  ::  [Tree a b] ->  Int ->     [ Tree a b ]  -> [ Tree a b ]
-     deq   ::                 Int ->     [ Tree a b ]  -> [ Tree a b ]
-
-     enqs      []                n       q             =        deq           n      q
-     enqs      (t:ts)            n       q
-           |  isBranch t                               =   t :  enqs  ts   (  n+1)   q
-           |  otherwise                                =        enqs  ts      n      q
-
-     deq                         0       _             =        []
-     deq                      (  n+1)    ( t :  q'  )  =        enqs  ts'     n      q'
-              where ts' = childrenOf t
-\end{code}
-\caption{Removing the repeated conditional branch}
-\label{levelOrder'2}
-\end{listing}
-
-\hiddencode{
-\begin{code}
-prop_levelOrder'2 n tree =
-        take n ( map (labelDisj id id) (levelOrder'   tree) )
-    ==  take n ( map (labelDisj id id) (levelOrder'2  tree) )
-\end{code}
-}
-
-Because the code in Listing~\ref{levelOrder'2} makes use of |childrenOf|,  it easily generalizes to arbitrary trees.   This code is very similar to a breath-first graph searching algorithm I wrote in December 2000,  simplified to trees.   This is notable because it was the day after I first read Richard Bird's classic paper, which is also prominently cited by Allison.
-
-\pagebreak
-
-Although I didn't become aware of Lloyd Allison's work until six years later,  at the time I had guessed that somebody had come up with it before.  It is a testament to Bird's writing that he has inspired at least two people,  and probably more, to independently arrive at the same idea.
-
-The code was rather difficult to write the first time,  but I immediately felt that I had a reasonable grasp of what was going on.   In fact, I remember part of the thought process behind my endeavor:   I was trying to implement a queue using naive list concatenation,  employing Richard Bird's technique to eliminate a quadratic number of passes.
-
-
-\subsection{Reusable Corecursive Queues}
-
-\begin{listing}[b]
-\begin{code}
-class Queue q where
-   empty :: q e
-   enque :: e -> q e -> q e
-   deque :: q e -> (Maybe e, q e)
-
-class Monad m => MonadQueue e m |  m -> e where
-   enQ  :: e -> m ()
-   deQ  :: m (Maybe e)
-\end{code}
-\caption{First-class versus monadic interfaces}
-\label{interfaces}
-\end{listing}
-
-We have now written three corecursive queues.  A natural question to ask is how to implement a reusable library for this technique,  so that we don't have to start from scratch every time we would like to use it.   This subsection informally derives such an implementation.
-
-What kind of interface would this library have?   The traditional interface treats queues as first class values,  as given by |Queue| in Figure~\ref{interfaces}.  Because Haskell is pure,  all first class values are persistent.   This gives us the freedom to enqueue an element,   back up,  enqueue a different element,  and use both  results in subsequent computations,  as demonstrated by the |fork a b q = (enque a q, enque b q)|.
-
-Due to implicit mutation, Allison's queues cannot be used persistently.  This implies that they cannot be first class values in a pure language!   Thus looking for an implementation of |enque| and |deque| is futile, as  any interface must enforce linearity upon enqueue.   Monadic interfaces offer a well-known solution to this problem,  so it seems plausible that we could find an implementation of a monadic interface.
-
-In the examples so far,  the logic that traverses the binary trees is entangled with the logic that defines the queue operations.   Our goal is to separate these concerns.  As the names suggest, |explore| in Listing~\ref{allison-code}  has no separation of concerns,   while |enqs| and |deqs| in Listing~\ref{levelOrder'2} isolate the basic operations into two mutually recursive functions.
-
-If we had an implementation of |enQ|,  it would be easy to write a helper function that takes a single tree,  and enqueues it iff it is a |Branch|.  Perhaps if we had this helper,  it would be easier to factor out the queue operations.    We will work backwards from this guess,  and forwards from |levelOrder'2| to write this single-element filter.
-
-Currently,  |enqs| loops over candidates to possibly enqueue.   By inlining |childrenOf| and then unrolling |enqs|,  we get two helper functions that differ only in their \emph{continuation}.     By parameterizing the continuation, we can refactor these into a single function.   Continuations are \emph{required} because every queue operation must return the resulting queue from the rest of the computation.   Thus every enqueue or dequeue must be aware of what operation comes next.  This process is demonstrated in Listings~\ref{unroll}~and~\ref{helper}.
-
-The resulting definition of |levelOrder'4| is easily the best means of expression thus far:  unlike |levelOrder'| and |levelOrder'3| it does not repeat any logic,  and unlike |levelOrder'2|,  the queue operations are expressed much more directly.    All that is left to do is to parameterize the continuation of |deq|,  and to remove the conditional branch from |enq|.   Once this is completed, we are left with a fully disentangled traversal in Listing~\ref{levelOrder'5}.
-
-\begin{listing}[p]
-\begin{code}
-levelOrder'3 tree = queue
-  where  queue = enq1 [tree] (0::Int) queue
-
-         enq2 [a,b]  n q  | isBranch a  = a :  (enq1 [b]  )  (  n+1)   q
-                          | otherwise   =      (enq1 [b]  )     n      q
-
-         enq1 [a]    n q  | isBranch a  = a :  (deq       )  (  n+1)   q
-                          | otherwise   =      (deq       )     n      q
-
-         deq  0                  _    = []
-         deq  n (Branch _ l r :  q')  = enq2 [l,r] (n-1) q'
-\end{code}
-\caption{Inlining |childrenOf| and unrolling |enqs|}
-\label{unroll}
-\end{listing}
-
-\begin{listing}[p]
-\begin{code}
-levelOrder'4 tree = queue
-  where  queue = (enq tree $ deq) (0::Int) queue
-
-         enq a k n q  | isBranch a  = a :  k  (  n+1  )  q
-                      | otherwise   =      k     n       q
-
-         deq 0                     _    = []
-         deq n  (  Branch _ l r :  q )  = (enq l $ enq r $ deq) (n-1) q
-\end{code}
-\caption{Parameterizing the continuations of |enq1| and |enq2|}
-\label{helper}
-\end{listing}
-
-
-\hiddencode{
-\begin{code}
-prop_levelOrder'3 n tree =
-        take n ( map (labelDisj id id) (levelOrder'   tree) )
-    ==  take n ( map (labelDisj id id) (levelOrder'3  tree) )
-
-prop_levelOrder'4 n tree =
-        take n ( map (labelDisj id id) (levelOrder'   tree) )
-    ==  take n ( map (labelDisj id id) (levelOrder'4  tree) )
-
-prop_levelOrder'5 tree n =
-        take n ( map (labelDisj id id) (levelOrder'   tree) )
-    ==  take n ( map (labelDisj id id) (levelOrder'5  tree) )
-\end{code}
-}
-
-
-\begin{listing}[p]
-\begin{code}
-levelOrder'5 tree = queue
-  where  queue = (handle tree $ (\() -> explore)) (0::Int) queue
-
-         handle t  | isBranch t  = enq t
-                   | otherwise   = ret ()
-
-         explore =  deq        $  (\(Branch _ l r) ->
-                    handle l   $  (\() ->
-                    handle r   $  (\() ->
-                    explore       )))
-
-         enq  e     k  n        q     =  e :  k  ()  (  n+1)  q
-
-         ret  a     k  n        q     =       k  a      n     q
-
-         deq        k  0        q     =       []
-         deq        k  n ( e :  q' )  =       k  e   (  n-1)  q'
-\end{code}
-\caption{A fully disentangled traversal in explicit CPS}
-\label{levelOrder'5}
-\end{listing}
-
-In a sense,  we have re-invented the traditional continuation passing style~\cite{eopl} (CPS) with a slight twist,  namely,  that the tail of a list is considered to be a tail call.   This is not a problem relative to the current understanding of the CPS transform,  where any part of the program that is guaranteed to terminate,  such as lazy cons~\cite{friedman87},   may optionally be left untouched by the transform.
-
-Now,  the only difference between |deq| and the monadic |deQ| is that the |deq| breaks out of it's loop and leaves the computation,  whereas |deQ| returns |Nothing| in this case.    Although the breaking out of the computation is superficially pleasing in this particular case,  there are good reasons to prefer the latter in most cases.   So we are ready to split Listing~\ref{levelOrder'5} into two parts:  reusable corecursive queue operations versus the breadth-first tree traversal in Listings~\ref{CorecQ} and~\ref{levelOrder''} respectively.
-
-\begin{listing}
-\begin{code}
-newtype  CorecQ e a
-      =  CorecQ (Cont (Int -> [e] -> [e]) a) deriving (Monad)
-
-mkCorecQ  x = (CorecQ (Cont x))
-unCorecQ  (CorecQ (Cont x)) =  x
-
-runCorecQ :: CorecQ element result -> [element]
-runCorecQ m =  queue
-        where  queue = unCorecQ m (\a n' q' -> []) 0 queue
-
-instance MonadQueue e (CorecQ e) where
-  enQ e  =  mkCorecQ  enq
-            where     enq k n      q    =  e :  k ()        (  n+1)  q
-  deQ    =  mkCorecQ  deq
-            where     deq k 0      q    =       k Nothing      0     q
-                      deq k n (e:  q')  =       k (Just e)  (  n-1)  q'
-
-\end{code}
-\caption{A reusable implementation of Allison's queue}
-\label{CorecQ}
-\end{listing}
-
-\begin{listing}
-\begin{code}
-levelOrder'' :: MonadQueue (Tree a b) q => Tree a b -> q ()
-levelOrder'' t = handle t >>= (\() -> explore)
-   where
-     handle t  | isBranch t  = enQ t
-               | otherwise   = return ()
-     explore =  deQ       >>=  maybe (return ()) (\(Branch _ l r)  ->
-                handle l  >>=  (\() ->
-                handle r  >>=  (\() ->
-                explore        )))
-\end{code}
-\caption{Traversing a binary tree using generic queues}
-\label{levelOrder''}
-\end{listing}
-
-I first wrote something like |CorecQ| in August 2005,  although it took me several years to understand my own code.  Of course, this raises the question of how one can write code that one doesn't understand.
-
-The answer is simple: type theory.   Following the reasoning at the beginning of this subsection,   I had been growing rather suspicious that corecursive queues could be abstracted via a monadic interface.  After reading Wouter Swierstra's ``Why Attribute Grammars Matter''~\cite{swierstra05} and coming to opinion that the examples contained therein are kind of lame,   I was motivated to produce better, more compelling examples.  Corecursive queues naturally came to mind.
-
-For ten hours I struggled, lost and confused,  starting over several times.  Eventually I came to realize that the state monad was not a suitable vehicle for Allison's technique,  and started thinking towards continuations.  Soon enough the types worked out and everything felt ``right.''    I was rather confident that it would work before I tried it.   And as if by magic,  it worked.
-
-The problem had to be simplified before I got anything working at all.   In the first three failed attempts, I tried to implement a full-blown |CorecQW|.   However,  fourth and first successful implementation could not even track the length of the queue internally,  rather, it was the client's responsibility to avoid the infinite nonproductive loop.
-
-\subsection {Observing Monadic Computations}
-
-Monadic computations must somehow be \emph{observed},  otherwise they are useless.  Note the type of |runCorecQ :: CorecQ e a -> [e]|.  The only observable aspect of the |CorecQ| monad is the list of enqueued elements.  In particular, the final return value |a| cannot be observed.
-
-Listing~\ref{byLevel} gives two generic combinators for level-order traversals.  They parameterize |childrenOf|, allowing arbitrary trees to be traversed.  In fact,  one need not even explicitly construct a tree: the Fibonacci trees could be traversed using this definition of |fibChildren|, for example.
-\begin{code}
-fibChildren 0  = []
-fibChildren 1  = [0,0]
-fibChildren n  = [n-2,n-1]
-\end{code}
-They also return a generic |MonadQueue|, allowing not only corecursive implementations, but also alternative implementations.   For example, more obvious implementations of |MonadQueue| include wrapping the traditional two-stack queue in a state monad,  or using explicitly mutable state as provided by |Control.Monad.ST|.   As we will see in the next section,  although these have the same semantics for |enQ| and |deQ|, they observe only the final return value.
-
-Thus, these combinators produce level-order traversals when observed by |runCorecQ|,  but are not particularly useful when observed with implementations that observe only return values.
-
-\begin{listing}
-\begin{code}
-byLevel,  byLevel' :: (MonadQueue a m) => (a -> [a]) -> [a] -> m ()
-
-byLevel childrenOf as = mapM_ enQ as >> explore
-  where
-    explore = deQ >>=  maybe (return ())
-                       (\a ->  do
-                               mapM_ enQ (childrenOf a  )
-                               explore                  )
-
-
-
-byLevel' childrenOf as = mapM_ handle as >> explore
-  where
-    handle a = when (hasChildren a) (enQ a)
-
-    explore = deQ >>=  maybe (return ())
-                       (\a ->  do
-                               mapM_ handle (childrenOf a  )
-                               explore                     )
-
-    hasChildren = not . null . childrenOf
-\end{code}
-\caption{Generic traversals over generic trees}
-\label{byLevel}
-\end{listing}
-
-There are two points worth noting about the definition of |byLevel| and |byLevel'|:  the top level definitions are not recursive,  and the recursive |explore| does not pass |childrenOf| to itself repeatedly.  This combination plays nice with the Glasgow Haskell Compiler as current implemented:  inlining |byLevel| opens up the possibility of inlining |childrenOf| as well, or at least eliminating an indirect jump.
-
-While this idiom can be worthwhile; it is far more important performance-wise that |enQ| and |deQ| be inlined.   Because we are using typeclasses to abstract over the queue operations,  inlining these operations is a clumsy thing to do in GHC.   Indeed,  ML-style functors are a superior choice for this type of abstraction.
-
-\hiddencode{
-\begin{spec}
-approx n = map (labelDisj id id) . take n
-
-prop_runCorecQ_runDebugQ_eq :: Eq a => Int -> (forall m ; (MonadQueue (Tree a a) m) => m ()) -> Bool
-prop_runCorecQ_runDebugQ_eq n m
-    =   approx n (runCorecQ m)
-    ==  approx n (runQueue m)
-
-prop_runCorecQ_levelOrder_eq n tree
-    =   approx n (levelOrder'2 tree)
-    ==  approx n (runCorecQ (byLevel' childrenOf [tree]))
-\end{spec}
-}
-
-
-\section{ Queues via explicit mutation }
-
-\begin{listing}[t]
-\begin{code}
-data   List     st a = Null | Cons a !(ListPtr st a)
-type   ListPtr  st a = STRef st (List st a)
-
-type     STQSt st r e = ListPtr st e -> ListPtr st e -> ST st r
-newtype  STQ e a
-     =  STQ { unSTQ :: forall r st . ((a -> STQSt st r e) -> STQSt st r e) }
-
-instance Monad (STQ e) where
-    return a  = STQ (\k -> k a)
-    m >>= f   = STQ (\k -> unSTQ m (\a -> unSTQ (f a) k))
-
-instance MonadQueue e (STQ e) where
-    enQ e  = STQ $ \k  a z -> do
-                       z' <- newSTRef Null
-                       writeSTRef z (Cons e z')
-                       k () a z'
-
-    deQ    = STQ $ \k  a z -> do
-                       list <- readSTRef a
-                       case list of
-                         Null         -> k Nothing   a   z
-                         (Cons e a')  -> k (Just e)  a'  z
-
-runSTQ :: STQ element result -> result
-runSTQ m = runST $ do
-  ref <- newSTRef Null
-  unSTQ m (\r _a _z -> return r) ref ref
-\end{code}
-\caption{Queues via Imperative Linked Lists}
-\label{STQ}
-\end{listing}
-
-Being able to efficiently implement real-time queues using monads is not particularly newsworthy,  as a knowledgeable programmer could always make use of  |Control.Monad.ST|,  which provides genuinely mutable state.   However, the point is that the corecursive implementation based on implicit mutation is \emph{shorter and safer} than an imperative linked list based on explicit mutation.   Moreover, |CorecQ| is \emph{faster} than |STQ| on current versions of GHC.
-
-In some cases,  arrays offer worthwhile constant-factor performance advantages over linked lists.   Thus,  barring other concerns such as concurrency,  the only explicitly mutable implementations of queues truly worth considering in Haskell are those that employ mutable arrays.
-
-Note the type |runSTQ :: STQ e a -> a|.   This observes the return result but does not observe anything about the queue elements.  With this in mind, even though |byLevel| visits leaves and |byLevel'| does not,  these combinators are observationally equivalent.  They both return |()| if the forest is a finite number of finite trees,  and diverge otherwise.
-
-If one is interested in things other than thermal output and timing information, a more conventional alternative to changing the monad would be to thread a value through |byLevel|.   Listing~\ref{foldrByLevel} defines |foldrByLevel|, a function for computing right folds over breadth-first traversals.
-
-Listing~\ref{use-cases} demonstrates how we can use |foldrByLevel| to concisely define various level order traversals over a forest of binary trees.  For example,  we can visit the labels of only leaves,  or only branches,  or both,  and these properties are reflected in the resulting types.
-
-\begin{listing}
-\begin{code}
-foldrByLevel  :: (MonadQueue a m)
-              => (a -> [a]) -> (a -> b -> b) -> b -> [a] -> m b
-foldrByLevel  childrenOf f b as = mapM_ enQ as >> explore
-   where
-     explore = deQ >>=  maybe (return b)
-                        (\a ->  do
-                                mapM_ enQ (childrenOf a  )
-                                b <- explore
-                                return (f a b)           )
-
-prop_foldrByLevel childrenOf f b as =
-       foldr f b (runCorecQ (byLevel childrenOf as))
-   ==  runSTQ (foldrByLevel childrenOf f b as)
-\end{code}
-\caption{Right folds over level-order traversals}
-\label{foldrByLevel}
-\end{listing}
-
-\begin{listing}
-\begin{code}
-foldrByLevel'  :: (MonadQueue a m)
-               => (a -> [a]) -> (a -> b -> b) -> b -> [a] -> m b
-foldrByLevel'  childrenOf f b as = handleMany as
-   where
-     handleMany []      = explore
-     handleMany (a:as)  = do
-         when (hasChildren a) (enQ a)
-         b <- handleMany as
-         return (f a b)
-
-     explore = deQ >>= maybe (return b) (handleMany . childrenOf)
-
-     hasChildren = not . null . childrenOf
-\end{code}
-\caption{A slightly lazier fold that does not enqueue leaves}
-\label{foldrByLevel'}
-\end{listing}
-
-\begin{listing}
-\begin{code}
-cid = const id
-
-getUnion     f = f childrenOf (labelDisj  (:)  (:)  ) []
-getLeaves    f = f childrenOf (labelDisj  (:)  cid  ) []
-getBranches  f = f childrenOf (labelDisj  cid  (:)  ) []
-\end{code}
-\begin{spec}
-runSTQ . getUnion     foldrByLevel :: [Tree a a] -> [a]
-runSTQ . getLeaves    foldrByLevel :: [Tree a b] -> [a]
-runSTQ . getBranches  foldrByLevel :: [Tree a b] -> [b]
-\end{spec}
-\caption{Handy functions and example use cases}
-\label{use-cases}
-\end{listing}
-
-There is no need for |foldrByLevel| to enqueue leaf nodes.   Instead of folding elements after they are dequeued,  we could instead fold elements before they are enqueued.   Listing~\ref{foldrByLevel'} computes the same fold, even though it enqueues branches only.
-
-An orthogonal change allows |foldrByLevel'| to be more lazy.  If the initial forest of trees is infinite,  |foldrByLevel| will get stuck in a nonproductive loop.   This is because Listing~\ref{foldrByLevel} enqueues the entire forest before doing any folding.   The enhanced version interleaves folding with enqueue operations.   Thus |foldrByLevel'| is a true generalization of |foldr|,  whereas the original is not.
-
-Of course, this property depends on the semantics of the monad:  the final result must be observed in a sufficiently lazy fashion.  This is not true of |runSTQ| even if the lazier variant of |ST| is used, and so |foldrByLevel| is semantically equivalent to |foldrByLevel'| relative to this monad.   This equivalency will be relaxed relative to |StateQ| in the next section.
-
-\hiddencode{
-\begin{spec}
-prop_foldr_ByLevel childrenOf f b as =
-       foldr f   b (runCorecQ (byLevel   childrenOf as))
-   ==  foldr f'  b (runCorecQ (byLevel'  childrenOf as))
-   where
-       f' a b = foldr f b (childrenOf a)
-\end{spec}
-}
-
-We now have four generic combinators and two ways to run each,  for a total of eight possibilities.  There is a pleasing combination of symmetry and anti-symmetry to this configuration:   if we use |runCorecQ| to observe the elements enqueued,  then |byLevel| is equivalent to |foldrByLevel|,  which differ from |byLevel'| and |foldrByLevel'|.  However, if we use |runSTQ| to observe the result,  then |byLevel| is equivalent to |byLevel'|,  which differ from |foldrByLevel| and |foldrByLevel'|.
-
-\section{Monad Transformers}
-
-This section briefly reviews the traditional two-stack queue,  and explores how they can be encapsulated inside a variety of different monads.   The first wraps the two-stack queue in a state monad,  thus guaranteeing amortized $\mathcal O(1)$ performance.  The second implementation employs a state transformer and a writer monad to observe both the elements enqueued and the final result.   The last introduces the continuation passing state monad,  which makes explicit an idiom already used in |CorecQ| and |STQ| of the previous sections.
-
-We explore the guarantees that various types of monads provide,  and demonstrate how most of these guarantees are lost when the monad transformers are used.  We argue that monad transformers are not robust abstractions,  culminating in the rather fragile corecursive queue transformer of the next section.
-
-\subsection{Two-Stack Queues}
-Purely functional stacks are easy because the simplest solution works well.    Due to sharing,  persistent linked lists make reasonably efficient stacks.  When pushing an element onto the stack,  all that is necessary is to allocate and initialize a single new |cons| cell.   Removing an element is a simple pointer dereference,  and involves no allocation.
-
-However, the same naive usage of lists leads to quadratic behavior.  Concatenating a single element onto the end of the list involves copying the entire list,  leading to $\mathcal O(n)$ enqueues.    Alternately,  one could store the queue in reverse,  which makes enqueue an $\mathcal O(1)$ operation,  but then peeking at or removing the front element then becomes a $\mathcal O(n)$ operation.
-
-Traditionally, purely functional queues combine these approaches.~\cite{okasaki98}  The queue is represented by two stacks:  the front stack and the back stack.   The front stack holds the beginning of the queue, and the back stack holds the remainder of the queue in reverse.   To enqueue something,  push it on the back stack.   To dequeue something,  pull it off the front stack.  If the front stack is subsequently empty, reverse the back stack onto the front.
-
-\begin{listing}[t]
-\begin{code}
-data TwoStackQ e = TwoStackQ [e] [e]
-
-instance Queue TwoStackQ where
-   empty = TwoStackQ [] []
-
-   enque z  (TwoStackQ []     [])  =   TwoStackQ [z]     []
-   enque z  (TwoStackQ (a:as) zs)  =   TwoStackQ (a:as)  (z:zs)
-
-   deque    (TwoStackQ []     [])  =   ( Nothing  ,  TwoStackQ []   []  )
-   deque    (TwoStackQ (a:as) zs)
-            |  null as             =   ( Just a   ,  TwoStackQ as'  []  )
-            |  otherwise           =   ( Just a   ,  TwoStackQ as   zs  )
-               where as' = reverse zs
-\end{code}
-\caption{Two-Stack Queues}
-\end{listing}
-
-Of course,  because two-stack queues are first-class values in Haskell,  they are automatically persistent.   Unlike an imperative language,  operations on the queue preserve older versions of the queue.   While |deque| is still $\mathcal O(n)$ in the worst case,  it works very well in practice because on average,  |deque| is actually $\mathcal O(1)$,  provided that the queue is not used persistently.   Under this assumption,  every element is moved at most once from the back to the front.
-
-There are implementations that guarantee $\mathcal O(1)$ worst-case operations,  even with persistent usage, such as Chris Okasaki's incremental reversals of lazy lists.~\cite{okasaki95}  However this solution has a relatively high constant factor,  in practice is often slower than other options,  sometimes significantly so.
-
-\subsection{The State Monad}
-
-\begin{listing}[t]
-\begin{code}
-newtype StateQ e a = StateQ (State (TwoStackQ e) a) deriving (Monad)
-
-instance MonadQueue e (StateQ e) where
-   enQ = StateQ . modify . enque
-   deQ = StateQ (State deque)
-
-runStateQ :: StateQ element result -> result
-runStateQ (StateQ m) =  let  (result, finalQ) = runState m empty
-                        in   result
-\end{code}
-\caption{First-class Queues inside |Control.Monad.State.Lazy|}
-\end{listing}
-
-Monadic interfaces can enforce linear, non-persistent usage of data structures, but do not necessarily do so.   The |StateQ| monad guarantees linearity by wrapping the queue in a |State| monad and hiding |get| and |put| operations,  ensuring amortized $\mathcal O(1)$ operations.  However,  the state transformer monad,  |StateT|,  cannot make this guarantee!  The ability to use state persistently can be recovered by choosing the nondeterministic list monad and lifting |MonadPlus| operations, for example.
-
-\subsection{The Writer Monad}
-
-\emph{Editorial Note} This section is deeply flawed.  In particular, the standard implementation of the Writer monad does not ensure the efficient use of list concatination.  A continuation-based implementation of the Writer monad, on the other hand,  does.  This confusion probably arose because the corecursive queue monad essentially uses a continuation-based writer monad to add elements to the queue.  For example,  compare the use of |mapCont| in the implementation of |enQ| for |CorecQ'| in Listing~\ref{CorecQ'} and the |MonadWriter| instance for |Cont| in~\cite{smith2010}. \emph{End Note}
-
-So far, we have only been able to observe either the enqueued elements or the final result, but not both.   We can employ the state transformer in conjunction with the Writer monad to observe both aspects of the computation.   The amortized $\mathcal O(1)$ guarantee is unaffected by the use of |Writer|.
-
-\begin{listing}[!b]
-\begin{code}
-newtype WriterQ e a
-     =  WriterQ (StateT (TwoStackQ e) (Writer [e])  a)
-        deriving (Monad)
-
-instance MonadQueue e (WriterQ e) where
-    enQ e  = WriterQ (tell [e] >> modify (enque e))
-    deQ    = WriterQ (StateT (return . deque))
-
-runWriterQ :: WriterQ element result -> (result, [element])
-runWriterQ (WriterQ m)
-    =  let  ((result, final_queue), queue) = runWriter (runStateT m empty)
-       in   (result, queue)
-\end{code}
-\caption{Observing the list of elements enqueued}
-\label{WriterQ}
-\end{listing}
-
-
-Writer monads partially enforce the efficient use of list concatenation.   In the MTL, |Writer [e] a| is just a newtype isomorphism for |([e],a)|.   It provides a function |tell| that takes a list and concatenates the remainder of the computation onto the end of the list.   This naturally associates to the right,  and thus avoids quadratic behavior.   Of course, |tell| accepts arbitrary length lists,  and one could inefficiently produce a long argument to |tell|.
-
-Note the duplication of functionality present in |WriterQ|.   Essentially,  the Writer monad re-creates the queue in a parallel data structure.   This observation was another motivation behind the creation of my first corecursive queue, analogous to Listing~\ref{levelOrder'2}.   I started writing a graph traversal using first-class queues,  producing a list of nodes as they were visited.   Although I was not using monads, I noticed the duplication and saw an opportunity to eliminate it using circular programming.
-
-
-\subsection{The Continuation Passing State Monad}
-
-\begin{listing}
-\begin{code}
-newtype CpSt st a
-      = CpSt { unCpSt :: forall res . (a -> st -> res) -> st -> res }
-
-instance Monad (CpSt st) where
-   return a  = CpSt (\k -> k a)
-   m >>= f   = CpSt (\k -> unCpSt m (\a -> unCpSt (f a) k))
-
-instance MonadState st (CpSt st) where
-   get       = CpSt (\k st  -> k st  st   )
-   put st'   = CpSt (\k _   -> k ()  st'  )
-
-runCpSt :: CpSt st a -> st -> (a,st)
-runCpSt m st = unCpSt m (\a st' -> (a,st')) st
-\end{code}
-\caption{A Continuation Passing State Monad}
-\label{CpSt}
-\end{listing}
-
-\begin{listing}
-\begin{code}
-newtype CpStQ r e a
-     =  CpStQ { unCpStQ :: StateT (TwoStackQ e) (Cont r) a }
-        deriving (Monad)
-
-instance MonadQueue e (CpStQ r e) where
-   enQ   = CpStQ . modify . enque
-   deQ   = CpStQ (StateT (return . deque))
-
-runCpStQ :: CpStQ r e r -> r
-runCpStQ (CpStQ m) = runCont (runStateT m empty) (\(r,q) -> r)
-\end{code}
-\caption{Queues via another continuation passing state monad}
-\label{CpStQ}
-\end{listing}
-
-\begin{listing}
-\begin{code}
-class MonadMapCC a m | m -> a where
-    mapCC :: (a -> a) -> m b -> m b
-
-instance MonadMapCC r (CpStQ r e) where
-    mapCC f = CpStQ . mapStateT (mapCont f) . unCpStQ
-
-
-foldrByLevel''  :: ( MonadQueue  a m
-                   , MonadMapCC  b m )
-                => (a -> [a]) -> (a -> b -> b) -> b -> [a] -> m b
-foldrByLevel''  childrenOf f b as = handleMany as
-   where
-     handleMany []      = explore
-     handleMany (a:as)  = do
-         when (hasChildren a) (enQ a)
-         mapCC (f a) (handleMany as)
-
-     explore = deQ >>= maybe (return b) (handleMany . childrenOf)
-
-     hasChildren = not . null . childrenOf
-\end{code}
-\caption{Restoring laziness to |foldrByLevel'| using |mapCont|}
-\label{foldrByLevel_}
-\end{listing}
-
-Less well known than the regular state monad is the continuation passing state monad, as shown in Listing~\ref{CpSt}.  This paper has already used this idiom twice.   It has been used to track the length and head of the queue inside |CorecQ|,  and to track the references to the start and end of the mutable list inside |STQ|.
-
-The lazy state monad is notoriously inefficient on current implementations of Haskell;  one is much better off using the strict state monad.  The continuation-passing state monad is even faster.  Compared to the lazy state monad, the biggest advantage is that we aren't returning many pairs of lazy tuples, at the cost of sacrificing some laziness.
-
-In the case of |CpSt|, a rank-2 type is used to hide the final result.  While this has little effect on the generated code,  it has profound consequences.  Specifically,  we cannot implement the control operators |callCC| and |mapCont|,  nor can we break out of the computation early.  However we can implement an |mfix| operator!  This last observation is due to Matt Morrow and will be demonstrated in Listing~\ref{fixpoints}.  As long as the computation terminates, the final continuation that |runCpSt| initially passes to the computation is guaranteed to be called exactly once.
-
-A nearly identical monad can be obtained by passing |Cont| as a parameter to |StateT|.  Other than the fact that the final result type is exposed,  the effect is the same as implementing |CpSt| in Listing~\ref{CpSt}.   In fact, when compiled {\tt ghc -O2},  the given operations compile into almost the same code.   The only significant, though minor, difference is that the continuation |a -> s -> r| is tupled and not curried.
-
-Listing~\ref{CpStQ} gives an implementation of the queue interface in terms of |StateT| and |Cont|.  However, |StateT| is \emph{lazy} but |CpStQ| is \emph{strict}!  Not only have we added a continuation semantics to |StateT|,  we have also changed part of the existing semantics.  This is in contrast to the use of |Writer| in |WriterQ|,  which left the state semantics undisturbed.  Not only are monad transformers not robust abstractions,  they are not robust in any sense of the word!
-
-More precisely,  |StateQ| returns its result incrementally while |CpStQ| doesn't return anything until the entire computation terminates.   This is easily observed on the Stern-Brocot tree:  |runStateQ (getBranches foldrByLevel [sternBrocot])|  returns useful data,  while |runCpStQ (getBranches foldrByLevel [sternBrocot])| gets stuck in an infinite nonproductive loop.
-
-Fortunately, incremental results can be recovered through the use of |mapCont|,  as illustrated in Listing~\ref{CpStQ}.   By tweaking |foldrByLevel| to use this control operator,  we can traverse the Stern-Brocot tree.   This would not be possible had we used the strict state monad,  or  hidden the final result type.
-
-
-
-
-\section{ Allison's Queues in Direct Style }
-
-\begin{listing}[p]
-\begin{code}
-getReader :: MonadReader a m => m a
-getReader    = ask
-
-setReader :: (MonadReader a m, MonadCont m) => a -> m ()
-setReader    = modReader . const
-
-modReader :: (MonadReader a m, MonadCont m) => (a -> a) -> m ()
-modReader f  = callCC (\k -> local f (k ()))
-
-stepReader :: (MonadReader a m, MonadCont m) => (a -> (b, a)) -> m b
-stepReader f = do
-                 st <- getReader
-                 let (r,st') = f st
-                 setReader st'
-                 return r
-\end{code}
-\caption{State effects with readers and |callCC|}
-\label{state}
-\end{listing}
-
-\begin{listing}[p]
-\begin{code}
-data Len a = Len !Int a
-
-deQ_len (Len  0          q    ) = (Nothing  , Len 0 q   )
-deQ_len (Len  (n+1) (e:  q')  ) = (Just e   , Len n q'  )
-
-inc_len (Len n head) = Len (n+1) head
-\end{code}
-\caption{Utility functions for tracking length}
-\end{listing}
-
-\begin{listing}[p]
-\begin{code}
-newtype CorecQ' e a
-     =  CorecQ' { unCorecQ' :: ContT [e] (Reader (Len [e])) a }
-        deriving (Monad)
-
-instance MonadQueue e (CorecQ' e) where
-    enQ e  = CorecQ' (mapContT (liftM (e:)) (modReader inc_len))
-    deQ    = CorecQ' (stepReader deQ_len)
-
-runCorecQ' :: CorecQ' e a -> [e]
-runCorecQ' (CorecQ' m) = q
-   where  q = runReader (runContT m endpoint) (Len 0 q)
-          endpoint _ = return []
-\end{code}
-\caption{Enqueue and dequeue in direct style}
-\label{CorecQ'}
-\end{listing}
-
-\hiddencode{
-\begin{spec}
-prop_runCorecQ_runCorecQ'_eq :: Eq a => Int -> (forall m . (MonadQueue (Tree a a) m) => m ()) -> Bool
-prop_runCorecQ_runCorecQ'_eq n m
-   =   approx n (runCorecQ   m)    ==  approx n (runCorecQ'  m)
-\end{spec}
-}
-
-
-There are two styles for programming with continuations.  The first is by explicitly by writing functions in the continuation passing style.  (CPS)  In this style,  all calls to non-primitive functions are tail calls, and functions have an extra continuation parameter,  which this paper has called |k|.   By contrast,  the direct style does not manipulate continuations explicitly,  but rather uses them implicitly or via control operators such as |callCC|, or |shift| and |reset|.
-
-This paper uses an extended CPS that allows the tail of a lazy cons to be considered a ``tail call'',  even though it is not a proper tail call.  In fact, the first four |levelOrder| variants are already written in this extended CPS,  albeit in a static form that does not parameterize the continuations.    They move towards a more direct style,  with only |enQ| and |deQ| written in an explicit,  parameterized CPS.
-
-Completing this process by writing |enQ| and |deQ| in direct style as well is a natural theoretical endeavor.   Of course,  |enQ| uses the lazy cons extension to CPS,  and in direct style this corresponds to |mapCont|.
-
-\begin{spec}
-mapCont :: (r -> r) -> Cont r a -> Cont r a
-mapCont f m = Cont (\k -> f (runCont m k))
-\end{spec}
-
-The type of our |CpSt| idiom is |(a -> s -> r) -> s -> r|,  which is isomorphic to |ContT r (Reader s) a|,  so this would be a plausible place to start.   Listing~\ref{state} demonstrates a way to implement state operation in terms of continuations and readers.  The function |ask| is defined in |Control.Monad.Reader| and retrieves the value from the reader,  while |local| takes a function and a monad,  and modifies the value in the reader during the execution of it's second argument.   The reader maintains it's original value otherwise.
-
-By using |callCC| to grab the entire remainder of the computation,  we can use |local| to mutate the reader.  With the addition of a few helper functions to manage the counter,  we are set up for concise definitions of |enQ| and |deQ| in direct style.
-
-
-\subsection{Independence of |mapCont|}
-
-The use of |mapCont| is notable because I am confident that |enQ| cannot be expressed in terms of |callCC|,  |(>>=)|,  and |return|.   The MTL's continuations are partially delimited,  as seems necessary for the general utility of |mapCont|.  However,  the analogous conjecture in terms of |shift| and |reset| is certainly not true.
-
-It may not be obvious why |mapCont| is independent of the rest,  but it turns out to be fairly trivial:   |callCC|, |(>>=)|, and |return| simply offer no way to add to the control context by introducing something that is not a proper tail call.   More formally,  we can modify the type of |CpSt|,  which uses higher-ranked types to hide the result type,  into a form that admits |callCC|,  but prohibits a useful form of |mapCont|.
-
-\begin{listing}
-\begin{code}
-newtype CpSt' s a
-      = CpSt' { runCpSt' :: forall r . (forall r'.  a -> s -> r') -> s -> r }
-
-instance Monad (CpSt' s) where
-  return a  = CpSt' (\k -> k a)
-  m >>= f   = CpSt' (\k -> runCpSt' m (\a -> runCpSt' (f a) k))
-
-instance MonadCont (CpSt' s) where
-  callCC f = CpSt' (\k -> runCpSt' (f (\a -> CpSt' (\_ -> k a))) k)
-
-mapCpSt' :: (forall a . a -> a) -> CpSt' s b -> CpSt' s b
-mapCpSt' f m  = CpSt' (\k -> f (runCpSt' m k))
-\end{code}
-\caption{A ``proof'' of the independence of |mapCont|}
-\label{independence}
-\end{listing}
-
-Note that the code in Listing~\ref{independence} is purely theoretical, not useful,  because computations inside of |CpSt'| cannot be observed without cheating.  The definitions are the same as the corresponding definitions of |Cont|.  Since the use of typeclasses are not essential, these definitions have meaning independent of their types.
-
-The types of |callCC|, |return|, and |(>>=)| are unchanged,  however the definition of |mapCont| gives a type error without providing an explicit higher-ranked type. Thanks to free theorems,  there are only three inhabitants of type |forall a . a->a|:  |id|, |const bot| and |bot|,  none of which are useful.   This argument may not be complete,  but I believe it can be the basis for a formal proof of independence.
-
-\subsection{Corecursive Queue Transformers}
-
-Now that |CorecQ| is in the direct style,  it is somewhat easier to come up with a plausible monad transformer.   Unfortunately,  |runCorecQT| is mostly broken.   For example,  as noted previously,  the corecursive queue implementation makes use of implicit mutation,  and thus depends on enforced linearity.   The non-deterministic list monad enables us to regain non-linear, persistent use.   Not surprisingly, the list monad is incompatible with this transformer.
-
-Those interested should experiment with which monads work and which don't.   Of particular interest is the |IO| monad.   Getting a simple variant of Unix's |tail| command to work properly around this transformer is an interesting exercise that presents some difficulty.
-
-\begin{listing}
-\begin{code}
-newtype CorecQT e m a
-      = CorecQT ( ContT (m [e]) (Reader (Len [e])) a )
-        deriving (Monad)
-
-instance Monad m => MonadQueue e (CorecQT e m) where
-   enQ z  = CorecQT (mapContT (liftM (liftM (z:))) (modReader inc_len))
-   deQ    = CorecQT (stepReader deQ_len)
-
-runCorecQT :: (MonadFix m) => CorecQT e m a -> m [e]
-runCorecQT m  = mfix (\q -> run m end_point (Len 0 q))
-  where
-    end_point _ = return (return [])
-    run (CorecQT m) k st = runReader (runContT m k) st
-\end{code}
-\caption{A rather fragile queue transformer}
-\end{listing}
-
-The |mfix :: a -> m a| used here is the topic of Levent Erk\"{o}k's Ph.D. thesis,  ``Value Recursion in Monadic Computations''.~\cite{erkok02}  The thesis argues that there is no |mfix| on continuations.    Note that this transformer does not contradict this conjecture,  as we are using  |mfix| to define the run operation,  not defining an |mfix| for |CorecQT|.
-
-Value recursion is also a primary topic of this paper,  however, our application requires the use of continuations.   Thus it would appear that we are discussing an alternate form of value recursion,  and that CPS enables some varieties of value recursion while disabling others.
-
-The |StateQ| monad is implemented via |State|,  which has an |mfix| operator.  Intuitively,  it would seem as though this |mfix| semantics makes sense for any |MonadQueue| implementation.  Whether or not a corecursive implementation can actually compute this semantics for |mfix| is a very interesting question.  Perhaps |CorecQ| would be a good avenue for research regarding Remark 5.2.1 on page 61 of Erk\"{o}k's thesis, speculating on the existence of special cases when continuations happen to have an |mfix|.
-
-Matt Morrow has observed that by hiding the result type of a continuation via higher-ranked types,  a |mfix| operator can in fact be implemented.   Of course, this technique also prohibits implementations of |callCC| and |mapCont|.  An |mfix| for |CpSt| is given in Listing~\ref{fixpoints}.   This does not directly contradict Erk\"{o}k's conjecture,  because the type of |CpSt| differs from |Cont|.  Currently,  this observation is a bit of a mystery, so this paper will not attempt to expound further.
-
-Also included in Listing~\ref{fixpoints} is the alternate fixpoint operator |mfixish| that is at the heart of this paper.  It does not have the same type as |mfix|; so neither does it contradict Erk\"{o}k's conjecture.
-
-\begin{listing}
-\begin{code}
-instance MonadFix (CpSt st) where
-   mfix f = CpSt (\k st -> let (a,st') = unCpSt (f a) (,) st in k a st')
-
-mfixish   :: (r -> Cont r a) -> Cont r a
-mfixish    f = Cont   (\k -> fix   (\r -> runCont   (f r) k))
-
-mfixishT  :: (MonadFix m) => (r -> ContT r m a) -> ContT r m a
-mfixishT   f = ContT  (\k -> mfix  (\r -> runContT  (f r) k))
-\end{code}
-\caption{Fixpoints for Value Recursion on Continuations}
-\label{fixpoints}
-\end{listing}
-
-One might assume, as this paper tacitly does, that there is no |mfix| over a monad implemented using continuations with an exposed return type.  This would imply that |CorecQ| cannot be used in conjunction with |CorecQT|,  ruling out an way that one might intuitively try to implement multiple queues.
-
-\section {Returning Results from Corecursive Queues}
-
-Thankfully,  |Control.Monad.Writer| is compatible with the queue transformer of the last section.   This enables us to observe results other than the queue itself.  The benefit is that we can now usefully execute |foldrByLevel| and its variants using corecursive queues.
-
-Unfortunately, because the writer monad expects monoids,  this approach isn't really suitable for preserving the result semantics of |STQ| and other implementations given in this paper.  The type |Writer e a| is just a newtype alias for |(a,e)|,  so instead of using our monad transformer directly,   we will simply use lazy pairs and start over.
-
-Because |CorecQW| can return results other than the queue,  it makes sense to implement |mapCont| and |mfixish| for this monad.  For a demonstration of |mfixishQW|,  we implement Chris Okasaki's breadth-first renumbering algorithm~\cite{okasaki00} in Listing~\ref{renum}.
-
-\begin{listing}
-\begin{code}
-newtype CorecQW w e a
-     =  CorecQW { unCorecQW :: ContT ([e],w) (Reader (Len [e])) a }
-        deriving (Monad)
-
-instance MonadQueue e (CorecQW w e) where
-  enQ e  = CorecQW (mapContT (liftM ((e:) *** id)) (modReader inc_len))
-  deQ    = CorecQW (stepReader deQ_len)
-
-instance MonadMapCC w (CorecQW w e) where
-  mapCC f = CorecQW . mapContT (liftM (id *** f)) . unCorecQW
-
-runCorecQW :: CorecQW w e w -> ([e],w)
-runCorecQW m = (q,w)
-    where  (q,w) = run m (\w -> return ([],w)) (Len 0 q)
-           run m k st = runReader (runContT (unCorecQW m) k) st
-
-mfixishQW :: (w -> CorecQW w e a) -> CorecQW w e a
-mfixishQW f = CorecQW (mfixishT (\ ~(q',w) -> unCorecQW (f w)))
-\end{code}
-\caption{Corecursive queues with return values}
-\label{CorecQW}
-\end{listing}
-
-
-Chris Okasaki's algorithm uses two queues and a stack to relabel a tree with increasing integers.  Our implementation makes use of two seperate,  corecursive queues in place of the first-class queues used in the original paper.   In both Chris Okasaki's original implementation and ours,  the stack is represented implicitly using the program stack.   As the stack guards the second queue from falling off the end and entering a nonproductive loop,  there is no need to track the length of this second queue explicitly.
-
-Although our rendering of Chris Okasaki's solution is \emph{implemented} using corecursion;  the function itself is \emph{not} corecursive.   It cannot renumber the Stern-Brocot tree, for example.   Instead it gets stuck in an infinite nonproductive loop.   For a truly corecursive implementation of breadth-first renumbering,  we recall Jones and Gibbons' solution~\cite{okasaki00}\cite{jones93} in Listing~\ref{lazyRenum}.
-
-\begin{listing}
-\begin{code}
-renum :: Integral int => Tree a b -> Tree int int
-renum t = last q2
-  where
-    (_, q2) = runCorecQW (mfixishQW (\q2 -> trav 0 q2 t >> return []))
-
-    trav n q t@(Leaf _)
-       =  do
-          q' <- mtrav (n+1) q
-          mapCC ((Leaf n):) (return q')
-    trav n q t@(Branch _ l r)
-       =  do
-          enQ l >> enQ r
-          mtrav (n+1) q >>= \(r':l':q') ->
-            mapCC ((Branch n l' r'):) (return q')
-
-    mtrav n q = deQ >>= maybe (return q) (trav n q)
-\end{code}
-\caption{Chris Okasaki's Breadth-First Renumbering Algorithm}
-\label{renum}
-\end{listing}
-
-\begin{listing}
-\begin{code}
-lazyRenum :: Integral int => Tree a b -> Tree int int
-lazyRenum t = t'
-   where
-     (ns, t') = loop (0:ns, t)
-
-     loop (n:ns,  Leaf    _      ) = (n+1:ns    , Leaf    n        )
-     loop (n:ns,  Branch  _ l r  ) = (n+1:ns''  , Branch  n l' r'  )
-       where
-         (ns'   , l')  = loop (ns   , l)
-         (ns''  , r')  = loop (ns'  , r)
-\end{code}
-\caption{Jones and Gibbons' Corecursive Renumbering Algorithm}
-\label{lazyRenum}
-\end{listing}
-
-\subsection{Performance of CorecQW}
-
-|CorecQW| exhibits a subtle performance discrepancy;  due to the fact that we are returning lazy pairs,  there are two paths of execution through the computation.   Which path is followed depends on whether the consumer is demanding elements of the queue,  or part of the result.  This concept is fairly well known among logic programmers,  but may be suprising to many functional programmers.
-
-When applied to the running example of breadth first search, returning lazy pairs incurs either about 25\% or 63\% abstraction penalty compared to the original |CorecQ|,  even if the extra result is |()|.  Eager programmers accustomed to quality implementations of ML and Scheme are used to returning multiple values with little or no undue overhead.  To be fair,  GHC performs similar optimizations on strict pairs~\cite{bgj04}, and neither Scheme nor ML offer lazy tuples nativly.   Supporting lazy tuples efficiently is a significantly harder problem.
-
-As a thought experiment,  I attempted to implement my own value return mechanism,  by starting with the original |CorecQ| and using |unsafePerformIO| and |IORefs| to open up a ``side channel.''  In the process,  I broke the full laziness optimization, \cite{santos95}  which must be turned off in order for this code to terminate.   It was instructive,   as I'm suspicious I ended up creating something similar to what GHC is already doing.
-
-The basic idea is that if we demand the result,  we enter a thunk which forces a small bit of queue computation, and then re-reads itself.   This process repeats until the queue computation terminates:  then the thunk gets replaced with a concrete value which gets returned the next time the thunk re-reads itself.   By enabling the trace output and running this code,  you can see it in action.
-
-The downside to this naive approach is that it exhibits an \emph{inversion of demand}.  The queue should be smart enough to realize that if a result is demanded, then it should demand it's own computation until a result (or part thereof) is returned,  saving a number of indirect jumps.
-
-\begin{listing}
-\begin{code}
-type QSt r e  = IORef r -> IORef [e] -> Int -> [e] -> [e]
-
-newtype Q r e a = Q { unQ :: ((a -> QSt r e) -> QSt r e) }
-
-instance Monad (Q r e) where
-    return a = Q ($a)
-    m >>= f  = Q (\k -> unQ m (\a -> unQ (f a) k))
-
-unsafeRead   ref    = unsafePerformIO (readIORef   ref    )
-unsafeWrite  ref a  = unsafePerformIO (writeIORef  ref a  )
-unsafeNew    a      = unsafePerformIO (newIORef    a      )
-
-instance Show e => MonadQueue e (Q r e) where
-  enQ x = Q (\k r e !n xs ->  let  xs' = (k () r e $! n+1) xs
-                              in   trace ("enQ $ " ++ show x)
-                                   (unsafeWrite e xs' `seq` (x:xs'))  )
-  deQ   = Q delta
-    where
-      delta k r e      0        xs   = k Nothing r e 0 xs
-      delta k r e (n+  1)  (x:  xs)  = trace  ("deQ " ++ show x)
-                                              (k (Just x) r e n xs)
-
-runQ m = (trace "reading return value" `seq` unsafeRead r (), queue)
-   where
-     r = unsafeNew init
-     init () = unsafePerformIO $ do
-                 trace "forcing computation\n" (return ())
-                 xs <- readIORef e
-                 force xs
-                 trace "reading return value\n" (return ())
-                 f <- readIORef r
-                 return (f ())
-     e  = unsafeNew queue
-     queue = unQ m breakK r e 0 queue
-
-force []     = return ()
-force (_:_)  = return ()
-
-breakK a r e n xs = trace  ("setting return value: " ++ show a)
-                           (unsafeWrite r (\() -> a) `seq` [])
-\end{code}
-\caption{Side channel thought experiment}
-\end{listing}
-
-Let me emphasize I am not advocating this style of programming, nor the use of this code!  In fact,  GHC's native tuples are faster!  This code is simply to demonstrate the two code paths,  and as such will produce different output depending on whether or not one demands the result.
-
-This experiment appears to be a constant factor slower than GHC's tuples.  It exhibits the same performance dissimilarity between the two code paths.  It appears to work in the presence of |callCC|, but only implements |mapCont| for the queue, not the result.   Thus an incremental |foldrByLevel| is not possible with this monad.
-
-\section{Performance Measurements}
-
-\begin{figure}
-\begin{center}
-\tabular{l r r r r r}
-Description & \multicolumn{2}{c}{Time} & \multicolumn{2}{c}{-H500M} & Bytes \\
-  & mean & $\sigma$ & mean & $\sigma$ &  \\ \hline
-levelOrder'      &  446 &  5 &   172 &  15 &  44.0 \\
-CorecQ           &  555 &  5 &   619 &   4 & 133.5 \\
-CorecQW \_       &  696 &  5 &  1128 &   6 & 213.6 \\
-CorecQW ()       &  907 & 56 &  2235 &  11 & 213.6 \\
-Side Channel \_  &  959 &  3 &  1171 &   7 & 228.7 \\
-Side Channel ()  & 1500 & 56 &  2171 &   7 & 276.4 \\
-STQ              & 1140 &  8 &  1087 &  14 & 371.2 \\
-TwoStack         & 1158 &  4 &   778 &  10 & 185.8 \\
-%  Wrapped in CpSt    & 1177 &  5 &   971 &   6 & 219.0 \\
-%  returning list     & 1345 &  8 &  1144 &   6 & 281.9 \\
-Okasaki          & 1553 &  7 &  1574 &  12 & 209.0 \\
-Data.Sequence    &  962 &  5 &  1308 &   5 & 348.1 \\
-%  return listing   & 1046 &  5 &  1525 &  11 & 412.5 \\
-\caption{Performance using GHC 6.10.3}
-\endtabular
-\end{center}
-\label{Test10}
-\end{figure}
-
-
-\begin{figure}
-\begin{center}
-\tabular{l r r r r r}
-Description & \multicolumn{2}{c}{Time} & \multicolumn{2}{c}{-H500M} & Bytes \\
-  & mean & $\sigma$ & mean & $\sigma$ &  \\ \hline
-levelOrder'      &  461 &  2 &   173 &  15 &  44.1 \\
-CorecQ           &  458 &  4 &   267 &  13 &  67.5 \\
-CorecQW \_       &  526 &  5 &   713 &   5 & 141.2 \\
-CorecQW ()       &  781 & 62 &  1775 &  62 & 141.3 \\
-\endtabular
-\caption{Performance using GHC 6.8.3}
-\end{center}
-\label{Test8}
-\end{figure}
-This was tested on an Intel Core 2 Duo T9550,  and both GHC 6.10.3 and 6.8.3.   The code that was used to produce these benchmarks is available on hackage as control-monad-queue.~\cite{smith-hackage09}  The results of the tests can be found in Figures~\ref{Test10} and 5.
-
-Each of the variants in the table were run on the $34^{\mbox{th}}$ fibonacci tree, which has 5.7 million branches.   The functions were run 20 times,  and the first few trials were discarded. The remaining trials were averaged,  and the standard deviation $\sigma$ was computed.  Timing information, presented in milliseconds, was gathered using |System.getCPUTime|,  which on the test system had a resolution of 10 milliseconds. The final column of the two tables gives the average number of bytes allocated for every |Branch|.
-
-Note that the code in this paper was not benchmarked directly for a variety of reasons. Each description is essentially equivalent to |levelOrder''| (Listing~\ref{levelOrder''}) run with the appropriate monad.   This means that the bottom four variants don't return anything useful.  While this isn't fair for implementing a drop-in replacement for |levelOrder' :: Tree a b -> [Tree a b]|,  it is more fair for comparing the relative performance of the queues themselves.
-
-The tests were also attempted using the {\tt -Hsize} option to set a suggested heap size and reduce the frequency of garbage collection;  this did indeed reduce the percentage of time spent in the garbage collector,  but this was usually more than offset in increased time spent in the mutator.
-
-\section{Related Work}
-
-The Glasgow Haskell Compiler provides |Data.Sequence|, which is based on 2-3 finger trees.~\cite{hinze06}  This offers amortized, asymptotically efficient operations to many kinds of operations on persistent sequences,  and is much more general data structure than a queue.
-
-Chris Okasaki~\cite{okasaki95} implements first-class real-time queues, even under persistent usage.  It is interesting that this solution also makes essential use of laziness,  and is based around the incremental reversal of lazy lists.
-
-Dariusz Biernacki, Olivier Danvy, and Chung-chieh Shan~\cite{biernacki06} have a clever way of implementing a queue using delimited continuations.   This employs the dynamic extent of |control| and |prompt|,  as opposed to the static extent of |shift| and |reset|.   This solution does not employ the use of circular programming.
-
-\section{Conclusions}
-
-For whatever reason,  Lloyd Allison's queue is not widely appreciated within the modern functional programming community.   This deserves to change,  as corecursive queues are both academically interesting and practical.  They are not as general as other queues,  but when they fit a problem,  they are an excellent choice.  Thus they occupy an interesting place in the functional programmer's toolbox.
-
-\section{Acknowledgements}
-
-I'd like to thank Amr Sabry and Olivier Danvy for particularly useful comments, Matt Hellige for a fun discussion that lead to the |unsafePerformIO| thought experiment, Matt Morrow for the insight that |mapCont| could not be implemented on |CpSt|,  Andres L\"oh for some assistance with LaTeX,  Stefan Ljungstrand for some criticism,  and others including Dan Friedman, Will Byrd, Aziz Ghuloum,  Ron Garcia, Roshan James, Michel Salim, and Michael Adams,  who enthusiastically endured my often inept attempts at explaining this work before I really understood it.
-
-I'd also like to acknowledge the giants whose shoulders made this work possible,  including Richard Bird, Philip Wadler,  Daniel Friedman and David Wise,  the designers and implementors of Haskell and the Monad Template Library,  and of course,  Robin Milner and  J. Roger Hindley.
-
-\raggedright
-\bibliography{CorecQueues}
-
-\end{document}
diff --git a/doc/fibtrees.tex b/doc/fibtrees.tex
deleted file mode 100644
--- a/doc/fibtrees.tex
+++ /dev/null
@@ -1,52 +0,0 @@
-{\fontsize{10}{12}
-\begin{tikzpicture}[level distance = 10mm]
-  \tikzstyle{level 1} = [level distance = 0]
-  \tikzstyle{level 2} = [sibling distance = 24mm, level distance = 10mm]
-  \tikzstyle{level 3} = [sibling distance = 12mm]
-  \tikzstyle{level 4} = [sibling distance = 6mm]
-  \tikzstyle{level 5} = [sibling distance = 4mm] 
-
-\node{}
-  child [sibling distance = 10mm] {
-   node {0}
-edge from parent[draw=none] } child [sibling distance = 11mm] {
-   node {0}
-edge from parent[draw=none] } child [sibling distance = 13mm] {
-   node {1}
-   child [sibling distance = 8mm] {node {0}}
-   child [sibling distance = 8mm] {node {0}}
-edge from parent[draw=none] } child [sibling distance = 18mm] {
-   node {2}
-   child [sibling distance = 10mm] {node {0}}
-   child [sibling distance = 10mm] {node {1}
-       child [sibling distance = 7mm] {node {0}}
-       child [sibling distance = 7mm] {node {0}}}
-edge from parent[draw=none] } child [sibling distance = 24.5mm] {
-   node {3}
-   child [sibling distance = 16mm] {node {1}
-          child [sibling distance = 8mm] {node {0}}
-          child [sibling distance = 8mm] {node {0}}}
-   child [sibling distance = 16mm] {node {2}
-          child [sibling distance = 8mm] {node {0}}
-          child [sibling distance = 8mm] {node {1}
-                 child [sibling distance = 6mm] {node {0}}
-                 child [sibling distance = 6mm] {node {0}}}}
-edge from parent[draw=none] } child [sibling distance = 29.5mm] {
-   node {4}
-   child {node {2}
-          child [sibling distance = 11mm] {node {0}}
-          child {node {1}
-                 child {node {0}}
-                 child {node {0}}}}
-   child {node {3}
-          child {node {1}
-                 child {node {0}}
-                 child {node {0}}}
-          child {node {2}
-                 child {node {0}}
-                 child {node {1}
-                        child {node {0}}
-                        child {node {0}}}}}
-edge from parent[draw=none] };
-\end{tikzpicture}
-}
diff --git a/doc/levelorder.tex b/doc/levelorder.tex
deleted file mode 100644
--- a/doc/levelorder.tex
+++ /dev/null
@@ -1,224 +0,0 @@
-{\fontsize{10}{12}
-\begin{tikzpicture}[level distance = 8mm, baseline=(current bounding box.north)]
-  \tikzstyle{level 1} = [sibling distance = 16mm]
-  \tikzstyle{level 2} = [sibling distance = 8mm]
-  \tikzstyle{level 3} = [sibling distance = 6mm]
-  \node {3}
-     child {node {1} 
-             child {node {0}}
-             child {node {0}}}
-     child {node {2}
-              child {node {0}}
-              child {node {1} child {node {0}}  child {node {0}}}};
-\end{tikzpicture}
-\hskip+1cm
-\begin{tikzpicture}[baseline=(current bounding box.north)]
-  \draw (0.00  cm, 0) node[anchor=text] (h) {3};
-  \draw (0.22  cm, 0) node[anchor=text]     {:};
-  \draw (0.35  cm, 0) node[anchor=text]     {explore 1};
-  \draw (1.85  cm, 0) node[anchor=text] (t) {$\boxdot$};
-
-  \draw [->] (t.mid) -- (t.north) -- +(0.1pt,1.5 mm) -| (h.north);
-
-
-  \draw (0.00  cm, -0.7 cm) node[anchor=text]     {3};
-  \draw (0.22  cm, -0.7 cm) node[anchor=text]     {:};
-  \draw (0.35  cm, -0.7 cm) node[anchor=text] (h) {1};
-  \draw (0.56  cm, -0.7 cm) node[anchor=text]     {:};
-  \draw (0.69  cm, -0.7 cm) node[anchor=text]     {2};
-  \draw (0.91  cm, -0.7 cm) node[anchor=text]     {:};
-  \draw (1.04  cm, -0.7 cm) node[anchor=text]     {explore 2};
-  \draw (2.54  cm, -0.7 cm) node[anchor=text] (t) {$\boxdot$};
-
-  \draw [->] (t.mid) -- (t.north) -- +(0.1pt,1.5 mm) -| (h.north);
-
-
-  \draw (0.00  cm, -1.4 cm) node[anchor=text]     {3};
-  \draw (0.22  cm, -1.4 cm) node[anchor=text]     {:};
-  \draw (0.35  cm, -1.4 cm) node[anchor=text]     {1};
-  \draw (0.56  cm, -1.4 cm) node[anchor=text]     {:};
-  \draw (0.69  cm, -1.4 cm) node[anchor=text] (h) {2};
-  \draw (0.91  cm, -1.4 cm) node[anchor=text]     {:};
-  \draw (1.04  cm, -1.4 cm) node[anchor=text]     {0};
-  \draw (1.26  cm, -1.4 cm) node[anchor=text]     {:};
-  \draw (1.39  cm, -1.4 cm) node[anchor=text]     {0};
-  \draw (1.61  cm, -1.4 cm) node[anchor=text]     {:};
-  \draw (1.74  cm, -1.4 cm) node[anchor=text]     {explore 3};
-  \draw (3.24  cm, -1.4 cm) node[anchor=text] (t) {$\boxdot$};
-
-  \draw [->] (t.mid) -- (t.north) -- +(0.1pt,1.5 mm) -| (h.north);
-
-
-  \draw (0.00  cm, -2.1 cm) node[anchor=text]     {3};
-  \draw (0.22  cm, -2.1 cm) node[anchor=text]     {:};
-  \draw (0.35  cm, -2.1 cm) node[anchor=text]     {1};
-  \draw (0.56  cm, -2.1 cm) node[anchor=text]     {:};
-  \draw (0.69  cm, -2.1 cm) node[anchor=text]     {2};
-  \draw (0.91  cm, -2.1 cm) node[anchor=text]     {:};
-  \draw (1.04  cm, -2.1 cm) node[anchor=text] (h) {0};
-  \draw (1.26  cm, -2.1 cm) node[anchor=text]     {:};
-  \draw (1.39  cm, -2.1 cm) node[anchor=text]     {0};
-  \draw (1.61  cm, -2.1 cm) node[anchor=text]     {:};
-  \draw (1.74  cm, -2.1 cm) node[anchor=text]     {0};
-  \draw (1.96  cm, -2.1 cm) node[anchor=text]     {:};
-  \draw (2.09  cm, -2.1 cm) node[anchor=text]     {1};
-  \draw (2.30  cm, -2.1 cm) node[anchor=text]     {:};
-  \draw (2.43  cm, -2.1 cm) node[anchor=text]     {explore 4};
-  \draw (3.93  cm, -2.1 cm) node[anchor=text] (t) {$\boxdot$};
-
-  \draw [->] (t.mid) -- (t.north) -- +(0.1pt,1.5 mm) -| (h.north);
-
-
-  \draw (0.00  cm, -2.8 cm) node[anchor=text]     {3};
-  \draw (0.22  cm, -2.8 cm) node[anchor=text]     {:};
-  \draw (0.35  cm, -2.8 cm) node[anchor=text]     {1};
-  \draw (0.56  cm, -2.8 cm) node[anchor=text]     {:};
-  \draw (0.69  cm, -2.8 cm) node[anchor=text]     {2};
-  \draw (0.91  cm, -2.8 cm) node[anchor=text]     {:};
-  \draw (1.04  cm, -2.8 cm) node[anchor=text]     {0};
-  \draw (1.26  cm, -2.8 cm) node[anchor=text]     {:};
-  \draw (1.39  cm, -2.8 cm) node[anchor=text] (h) {0};
-  \draw (1.61  cm, -2.8 cm) node[anchor=text]     {:};
-  \draw (1.74  cm, -2.8 cm) node[anchor=text]     {0};
-  \draw (1.96  cm, -2.8 cm) node[anchor=text]     {:};
-  \draw (2.09  cm, -2.8 cm) node[anchor=text]     {1};
-  \draw (2.30  cm, -2.8 cm) node[anchor=text]     {:};
-  \draw (2.43  cm, -2.8 cm) node[anchor=text]     {explore 3};
-  \draw (3.93  cm, -2.8 cm) node[anchor=text] (t) {$\boxdot$};
-
-  \draw [->] (t.mid) -- (t.north) -- +(0.1pt,1.5 mm) -| (h.north);
-
-
-  \draw (0.00  cm, -3.5 cm) node[anchor=text]     {3};
-  \draw (0.22  cm, -3.5 cm) node[anchor=text]     {:};
-  \draw (0.35  cm, -3.5 cm) node[anchor=text]     {1};
-  \draw (0.56  cm, -3.5 cm) node[anchor=text]     {:};
-  \draw (0.69  cm, -3.5 cm) node[anchor=text]     {2};
-  \draw (0.91  cm, -3.5 cm) node[anchor=text]     {:};
-  \draw (1.04  cm, -3.5 cm) node[anchor=text]     {0};
-  \draw (1.26  cm, -3.5 cm) node[anchor=text]     {:};
-  \draw (1.39  cm, -3.5 cm) node[anchor=text]     {0};
-  \draw (1.61  cm, -3.5 cm) node[anchor=text]     {:};
-  \draw (1.74  cm, -3.5 cm) node[anchor=text] (h) {0};
-  \draw (1.96  cm, -3.5 cm) node[anchor=text]     {:};
-  \draw (2.09  cm, -3.5 cm) node[anchor=text]     {1};
-  \draw (2.30  cm, -3.5 cm) node[anchor=text]     {:};
-  \draw (2.43  cm, -3.5 cm) node[anchor=text]     {explore 2};
-  \draw (3.93  cm, -3.5 cm) node[anchor=text] (t) {$\boxdot$};
-
-  \draw [->] (t.mid) -- (t.north) -- +(0.1pt,1.5 mm) -| (h.north);
-
-
-  \draw (0.00  cm, -4.2 cm) node[anchor=text]     {3};
-  \draw (0.22  cm, -4.2 cm) node[anchor=text]     {:};
-  \draw (0.35  cm, -4.2 cm) node[anchor=text]     {1};
-  \draw (0.56  cm, -4.2 cm) node[anchor=text]     {:};
-  \draw (0.71  cm, -4.2 cm) node[anchor=text]     {2};
-  \draw (0.91  cm, -4.2 cm) node[anchor=text]     {:};
-  \draw (1.04  cm, -4.2 cm) node[anchor=text]     {0};
-  \draw (1.26  cm, -4.2 cm) node[anchor=text]     {:};
-  \draw (1.39  cm, -4.2 cm) node[anchor=text]     {0};
-  \draw (1.61  cm, -4.2 cm) node[anchor=text]     {:};
-  \draw (1.74  cm, -4.2 cm) node[anchor=text]     {0};
-  \draw (1.96  cm, -4.2 cm) node[anchor=text]     {:};
-  \draw (2.09  cm, -4.2 cm) node[anchor=text] (h) {1};
-  \draw (2.30  cm, -4.2 cm) node[anchor=text]     {:};
-  \draw (2.43  cm, -4.2 cm) node[anchor=text]     {explore 1};
-  \draw (3.93  cm, -4.2 cm) node[anchor=text] (t) {$\boxdot$};
-
-  \draw [->] (t.mid) -- (t.north) -- +(0.1pt,1.5 mm) -| (h.north);
-
-
-  \draw (0.00  cm, -4.9 cm) node[anchor=text]     {3};
-  \draw (0.22  cm, -4.9 cm) node[anchor=text]     {:};
-  \draw (0.35  cm, -4.9 cm) node[anchor=text]     {1};
-  \draw (0.56  cm, -4.9 cm) node[anchor=text]     {:};
-  \draw (0.69  cm, -4.9 cm) node[anchor=text]     {2};
-  \draw (0.91  cm, -4.9 cm) node[anchor=text]     {:};
-  \draw (1.04  cm, -4.9 cm) node[anchor=text]     {0};
-  \draw (1.26  cm, -4.9 cm) node[anchor=text]     {:};
-  \draw (1.39  cm, -4.9 cm) node[anchor=text]     {0};
-  \draw (1.61  cm, -4.9 cm) node[anchor=text]     {:};
-  \draw (1.74  cm, -4.9 cm) node[anchor=text]     {0};
-  \draw (1.96  cm, -4.9 cm) node[anchor=text]     {:};
-  \draw (2.09  cm, -4.9 cm) node[anchor=text]     {1};
-  \draw (2.30  cm, -4.9 cm) node[anchor=text]     {:};
-  \draw (2.43  cm, -4.9 cm) node[anchor=text] (h) {0};
-  \draw (2.65  cm, -4.9 cm) node[anchor=text]     {:};
-  \draw (2.78  cm, -4.9 cm) node[anchor=text]     {0};
-  \draw (3.00  cm, -4.9 cm) node[anchor=text]     {:};
-  \draw (3.13  cm, -4.9 cm) node[anchor=text]     {explore 2};
-  \draw (4.63  cm, -4.9 cm) node[anchor=text] (t) {$\boxdot$};
-
-  \draw [->] (t.mid) -- (t.north) -- +(0.1pt,1.5 mm) -| (h.north);
-
-
-  \draw (0.00  cm, -5.6 cm) node[anchor=text]     {3};
-  \draw (0.22  cm, -5.6 cm) node[anchor=text]     {:};
-  \draw (0.35  cm, -5.6 cm) node[anchor=text]     {1};
-  \draw (0.56  cm, -5.6 cm) node[anchor=text]     {:};
-  \draw (0.69  cm, -5.6 cm) node[anchor=text]     {2};
-  \draw (0.91  cm, -5.6 cm) node[anchor=text]     {:};
-  \draw (1.04  cm, -5.6 cm) node[anchor=text]     {0};
-  \draw (1.26  cm, -5.6 cm) node[anchor=text]     {:};
-  \draw (1.39  cm, -5.6 cm) node[anchor=text]     {0};
-  \draw (1.61  cm, -5.6 cm) node[anchor=text]     {:};
-  \draw (1.74  cm, -5.6 cm) node[anchor=text]     {0};
-  \draw (1.96  cm, -5.6 cm) node[anchor=text]     {:};
-  \draw (2.09  cm, -5.6 cm) node[anchor=text]     {1};
-  \draw (2.30  cm, -5.6 cm) node[anchor=text]     {:};
-  \draw (2.43  cm, -5.6 cm) node[anchor=text]     {0};
-  \draw (2.65  cm, -5.6 cm) node[anchor=text]     {:};
-  \draw (2.78  cm, -5.6 cm) node[anchor=text] (h) {0};
-  \draw (3.00  cm, -5.6 cm) node[anchor=text]     {:};
-  \draw (3.13  cm, -5.6 cm) node[anchor=text]     {explore 1};
-  \draw (4.63  cm, -5.6 cm) node[anchor=text] (t) {$\boxdot$};
-
-  \draw [->] (t.mid) -- (t.north) -- +(0.1pt,1.5 mm) -| (h.north);
-
-
-  \draw (0.00  cm, -6.3 cm) node[anchor=text]     {3};
-  \draw (0.22  cm, -6.3 cm) node[anchor=text]     {:};
-  \draw (0.35  cm, -6.3 cm) node[anchor=text]     {1};
-  \draw (0.56  cm, -6.3 cm) node[anchor=text]     {:};
-  \draw (0.69  cm, -6.3 cm) node[anchor=text]     {2};
-  \draw (0.91  cm, -6.3 cm) node[anchor=text]     {:};
-  \draw (1.04  cm, -6.3 cm) node[anchor=text]     {0};
-  \draw (1.26  cm, -6.3 cm) node[anchor=text]     {:};
-  \draw (1.39  cm, -6.3 cm) node[anchor=text]     {0};
-  \draw (1.61  cm, -6.3 cm) node[anchor=text]     {:};
-  \draw (1.74  cm, -6.3 cm) node[anchor=text]     {0};
-  \draw (1.96  cm, -6.3 cm) node[anchor=text]     {:};
-  \draw (2.09  cm, -6.3 cm) node[anchor=text]     {1};
-  \draw (2.30  cm, -6.3 cm) node[anchor=text]     {:};
-  \draw (2.43  cm, -6.3 cm) node[anchor=text]     {0};
-  \draw (2.65  cm, -6.3 cm) node[anchor=text]     {:};
-  \draw (2.78  cm, -6.3 cm) node[anchor=text]     {0};
-  \draw (3.00  cm, -6.3 cm) node[anchor=text]     {:};
-  \draw (3.13  cm, -6.3 cm) node[anchor=text] (h) {explore 0};
-  \draw (4.63  cm, -6.3 cm) node[anchor=text] (t) {$\boxdot$};
-
-  \draw [->] (t.mid) -- (t.north) -- +(0.1pt,1.5 mm) -| (h.north);
-
-
-  \draw (0.00  cm, -7.0 cm) node[anchor=text]     {3};
-  \draw (0.22  cm, -7.0 cm) node[anchor=text]     {:};
-  \draw (0.35  cm, -7.0 cm) node[anchor=text]     {1};
-  \draw (0.56  cm, -7.0 cm) node[anchor=text]     {:};
-  \draw (0.69  cm, -7.0 cm) node[anchor=text]     {2};
-  \draw (0.91  cm, -7.0 cm) node[anchor=text]     {:};
-  \draw (1.04  cm, -7.0 cm) node[anchor=text]     {0};
-  \draw (1.26  cm, -7.0 cm) node[anchor=text]     {:};
-  \draw (1.39  cm, -7.0 cm) node[anchor=text]     {0};
-  \draw (1.61  cm, -7.0 cm) node[anchor=text]     {:};
-  \draw (1.74  cm, -7.0 cm) node[anchor=text]     {0};
-  \draw (1.96  cm, -7.0 cm) node[anchor=text]     {:};
-  \draw (2.09  cm, -7.0 cm) node[anchor=text]     {1};
-  \draw (2.30  cm, -7.0 cm) node[anchor=text]     {:};
-  \draw (2.43  cm, -7.0 cm) node[anchor=text]     {0};
-  \draw (2.65  cm, -7.0 cm) node[anchor=text]     {:};
-  \draw (2.78  cm, -7.0 cm) node[anchor=text]     {0};
-  \draw (3.00  cm, -7.0 cm) node[anchor=text]     {:};
-  \draw (3.13  cm, -7.0 cm) node[anchor=text]     {[]};
-\end{tikzpicture}
-}
diff --git a/doc/sternbrocot.tex b/doc/sternbrocot.tex
deleted file mode 100644
--- a/doc/sternbrocot.tex
+++ /dev/null
@@ -1,38 +0,0 @@
-\begin{tikzpicture}[level distance = 10mm]
-  \tikzstyle{level 1} = [sibling distance = 64mm]
-  \tikzstyle{level 2} = [sibling distance = 32mm]
-  \tikzstyle{level 3} = [sibling distance = 16mm]
-  \tikzstyle{level 4} = [sibling distance = 8mm]
-  \tikzstyle{level 5} = [sibling distance = 2.2mm, level distance = 5.5mm] 
-  \node {$\frac{1}{1}$}
-   child {node {$\frac{1}{2}$}
-          child {node {$\frac{1}{3}$}
-                 child {node {$\frac{1}{4}$}
-                        child {node {$\frac{1}{5}$} child {} child {}}
-                        child {node {$\frac{2}{7}$} child {} child {}}}
-                 child {node {$\frac{2}{5}$}
-                        child {node {$\frac{3}{8}$} child {} child {}}
-                        child {node {$\frac{3}{7}$} child {} child {}}}}
-          child {node {$\frac{2}{3}$}
-                 child {node {$\frac{3}{5}$}
-                        child {node {$\frac{4}{7}$} child {} child {}}
-                        child {node {$\frac{5}{8}$} child {} child {}}}
-                 child {node {$\frac{3}{4}$}
-                        child {node {$\frac{5}{7}$} child {} child {}}
-                        child {node {$\frac{4}{5}$} child {} child {}}}}}
-   child {node {$\frac{2}{1}$}
-          child {node {$\frac{3}{2}$}
-                 child {node {$\frac{4}{3}$}
-                        child {node {$\frac{5}{4}$} child {} child {}}
-                        child {node {$\frac{7}{5}$} child {} child {}}}
-                 child {node {$\frac{5}{3}$}
-                        child {node {$\frac{8}{5}$} child {} child {}}
-                        child {node {$\frac{7}{4}$} child {} child {}}}}
-          child {node {$\frac{3}{1}$}
-                 child {node {$\frac{5}{2}$}
-                        child {node {$\frac{7}{3}$} child {} child {}}
-                        child {node {$\frac{8}{3}$} child {} child {}}}
-                 child {node {$\frac{4}{1}$}
-                        child {node {$\frac{7}{2}$} child {} child {}}
-                        child {node {$\frac{5}{1}$} child {} child {}}}}};
-\end{tikzpicture}
diff --git a/doc/tmr.bst b/doc/tmr.bst
deleted file mode 100644
--- a/doc/tmr.bst
+++ /dev/null
@@ -1,1268 +0,0 @@
-%%
-%% This is file `tmr.bst',
-%% generated with the docstrip utility.
-%%
-%% The original source files were:
-%%
-%% merlin.mbs  (with options: `lang,seq-no,ed-au,yr-par,jwdpg,num-xser,numser,edpar,xedn,etal-it,url,url-blk,nfss,')
-%% ----------------------------------------
-%% *** bibliography style for The Monad.Reader ***
-%% 
-%% Copyright 1994-2003 Patrick W Daly
- % ===============================================================
- % IMPORTANT NOTICE:
- % This bibliographic style (bst) file has been generated from one or
- % more master bibliographic style (mbs) files, listed above.
- %
- % This generated file can be redistributed and/or modified under the terms
- % of the LaTeX Project Public License Distributed from CTAN
- % archives in directory macros/latex/base/lppl.txt; either
- % version 1 of the License, or any later version.
- % ===============================================================
- % Name and version information of the main mbs file:
- % \ProvidesFile{merlin.mbs}[2003/09/8 4.12 (PWD, AO, DPC)]
- %   For use with BibTeX version 0.99a or later
- %-------------------------------------------------------------------
- % This bibliography style file is intended for texts in ENGLISH
- % This is a numerical citation style, and as such is standard LaTeX.
- % It requires no extra package to interface to the main text.
- % The form of the \bibitem entries is
- %   \bibitem{key}...
- % Usage of \cite is as follows:
- %   \cite{key} ==>>          [#]
- %   \cite[chap. 2]{key} ==>> [#, chap. 2]
- % where # is a number determined by the ordering in the reference list.
- % The order in the reference list is that by which the works were originally
- %   cited in the text, or that in the database.
- %---------------------------------------------------------------------
-
-ENTRY
-  { address
-    author
-    booktitle
-    chapter
-    edition
-    editor
-    eid
-    howpublished
-    institution
-    journal
-    key
-    language
-    month
-    note
-    number
-    organization
-    pages
-    publisher
-    school
-    series
-    title
-    type
-    url
-    volume
-    year
-  }
-  {}
-  { label }
-INTEGERS { output.state before.all mid.sentence after.sentence after.block }
-FUNCTION {init.state.consts}
-{ #0 'before.all :=
-  #1 'mid.sentence :=
-  #2 'after.sentence :=
-  #3 'after.block :=
-}
-STRINGS { s t}
-FUNCTION {output.nonnull}
-{ 's :=
-  output.state mid.sentence =
-    { ", " * write$ }
-    { output.state after.block =
-        { add.period$ write$
-          newline$
-          "\newblock " write$
-        }
-        { output.state before.all =
-            'write$
-            { add.period$ " " * write$ }
-          if$
-        }
-      if$
-      mid.sentence 'output.state :=
-    }
-  if$
-  s
-}
-FUNCTION {output}
-{ duplicate$ empty$
-    'pop$
-    'output.nonnull
-  if$
-}
-FUNCTION {output.check}
-{ 't :=
-  duplicate$ empty$
-    { pop$ "empty " t * " in " * cite$ * warning$ }
-    'output.nonnull
-  if$
-}
-FUNCTION {fin.entry}
-{ add.period$
-  write$
-  newline$
-}
-
-FUNCTION {new.block}
-{ output.state before.all =
-    'skip$
-    { after.block 'output.state := }
-  if$
-}
-FUNCTION {new.sentence}
-{ output.state after.block =
-    'skip$
-    { output.state before.all =
-        'skip$
-        { after.sentence 'output.state := }
-      if$
-    }
-  if$
-}
-FUNCTION {add.blank}
-{  " " * before.all 'output.state :=
-}
-
-FUNCTION {date.block}
-{
-  new.block
-}
-
-FUNCTION {not}
-{   { #0 }
-    { #1 }
-  if$
-}
-FUNCTION {and}
-{   'skip$
-    { pop$ #0 }
-  if$
-}
-FUNCTION {or}
-{   { pop$ #1 }
-    'skip$
-  if$
-}
-FUNCTION {new.block.checka}
-{ empty$
-    'skip$
-    'new.block
-  if$
-}
-FUNCTION {new.block.checkb}
-{ empty$
-  swap$ empty$
-  and
-    'skip$
-    'new.block
-  if$
-}
-FUNCTION {new.sentence.checka}
-{ empty$
-    'skip$
-    'new.sentence
-  if$
-}
-FUNCTION {new.sentence.checkb}
-{ empty$
-  swap$ empty$
-  and
-    'skip$
-    'new.sentence
-  if$
-}
-FUNCTION {field.or.null}
-{ duplicate$ empty$
-    { pop$ "" }
-    'skip$
-  if$
-}
-FUNCTION {emphasize}
-{ duplicate$ empty$
-    { pop$ "" }
-    { "\emph{" swap$ * "}" * }
-  if$
-}
-FUNCTION {tie.or.space.prefix}
-{ duplicate$ text.length$ #3 <
-    { "~" }
-    { " " }
-  if$
-  swap$
-}
-
-FUNCTION {capitalize}
-{ "u" change.case$ "t" change.case$ }
-
-FUNCTION {space.word}
-{ " " swap$ * " " * }
- % Here are the language-specific definitions for explicit words.
- % Each function has a name bbl.xxx where xxx is the English word.
- % The language selected here is ENGLISH
-FUNCTION {bbl.and}
-{ "and"}
-
-FUNCTION {bbl.etal}
-{ "et~al." }
-
-FUNCTION {bbl.editors}
-{ "editors" }
-
-FUNCTION {bbl.editor}
-{ "editor" }
-
-FUNCTION {bbl.edby}
-{ "edited by" }
-
-FUNCTION {bbl.edition}
-{ "edition" }
-
-FUNCTION {bbl.volume}
-{ "volume" }
-
-FUNCTION {bbl.of}
-{ "of" }
-
-FUNCTION {bbl.number}
-{ "number" }
-
-FUNCTION {bbl.nr}
-{ "no." }
-
-FUNCTION {bbl.in}
-{ "in" }
-
-FUNCTION {bbl.pages}
-{ "pages" }
-
-FUNCTION {bbl.page}
-{ "page" }
-
-FUNCTION {bbl.chapter}
-{ "chapter" }
-
-FUNCTION {bbl.techrep}
-{ "Technical Report" }
-
-FUNCTION {bbl.mthesis}
-{ "Master's thesis" }
-
-FUNCTION {bbl.phdthesis}
-{ "Ph.D. thesis" }
-
-MACRO {jan} {"January"}
-
-MACRO {feb} {"February"}
-
-MACRO {mar} {"March"}
-
-MACRO {apr} {"April"}
-
-MACRO {may} {"May"}
-
-MACRO {jun} {"June"}
-
-MACRO {jul} {"July"}
-
-MACRO {aug} {"August"}
-
-MACRO {sep} {"September"}
-
-MACRO {oct} {"October"}
-
-MACRO {nov} {"November"}
-
-MACRO {dec} {"December"}
-
-MACRO {acmcs} {"ACM Computing Surveys"}
-
-MACRO {acta} {"Acta Informatica"}
-
-MACRO {cacm} {"Communications of the ACM"}
-
-MACRO {ibmjrd} {"IBM Journal of Research and Development"}
-
-MACRO {ibmsj} {"IBM Systems Journal"}
-
-MACRO {ieeese} {"IEEE Transactions on Software Engineering"}
-
-MACRO {ieeetc} {"IEEE Transactions on Computers"}
-
-MACRO {ieeetcad}
- {"IEEE Transactions on Computer-Aided Design of Integrated Circuits"}
-
-MACRO {ipl} {"Information Processing Letters"}
-
-MACRO {jacm} {"Journal of the ACM"}
-
-MACRO {jcss} {"Journal of Computer and System Sciences"}
-
-MACRO {scp} {"Science of Computer Programming"}
-
-MACRO {sicomp} {"SIAM Journal on Computing"}
-
-MACRO {tocs} {"ACM Transactions on Computer Systems"}
-
-MACRO {tods} {"ACM Transactions on Database Systems"}
-
-MACRO {tog} {"ACM Transactions on Graphics"}
-
-MACRO {toms} {"ACM Transactions on Mathematical Software"}
-
-MACRO {toois} {"ACM Transactions on Office Information Systems"}
-
-MACRO {toplas} {"ACM Transactions on Programming Languages and Systems"}
-
-MACRO {tcs} {"Theoretical Computer Science"}
-FUNCTION {bibinfo.check}
-{ swap$
-  duplicate$ missing$
-    {
-      pop$ pop$
-      ""
-    }
-    { duplicate$ empty$
-        {
-          swap$ pop$
-        }
-        { swap$
-          pop$
-        }
-      if$
-    }
-  if$
-}
-FUNCTION {bibinfo.warn}
-{ swap$
-  duplicate$ missing$
-    {
-      swap$ "missing " swap$ * " in " * cite$ * warning$ pop$
-      ""
-    }
-    { duplicate$ empty$
-        {
-          swap$ "empty " swap$ * " in " * cite$ * warning$
-        }
-        { swap$
-          pop$
-        }
-      if$
-    }
-  if$
-}
-FUNCTION {format.url}
-{ url empty$
-    { "" }
-    { "\urlprefix\url{" url * "}" * }
-  if$
-}
-
-STRINGS  { bibinfo}
-INTEGERS { nameptr namesleft numnames }
-
-FUNCTION {format.names}
-{ 'bibinfo :=
-  duplicate$ empty$ 'skip$ {
-  's :=
-  "" 't :=
-  #1 'nameptr :=
-  s num.names$ 'numnames :=
-  numnames 'namesleft :=
-    { namesleft #0 > }
-    { s nameptr
-      "{ff~}{vv~}{ll}{, jj}"
-      format.name$
-      bibinfo bibinfo.check
-      't :=
-      nameptr #1 >
-        {
-          namesleft #1 >
-            { ", " * t * }
-            {
-              numnames #2 >
-                { "," * }
-                'skip$
-              if$
-              s nameptr "{ll}" format.name$ duplicate$ "others" =
-                { 't := }
-                { pop$ }
-              if$
-              t "others" =
-                {
-                  " " * bbl.etal emphasize *
-                }
-                {
-                  bbl.and
-                  space.word * t *
-                }
-              if$
-            }
-          if$
-        }
-        't
-      if$
-      nameptr #1 + 'nameptr :=
-      namesleft #1 - 'namesleft :=
-    }
-  while$
-  } if$
-}
-FUNCTION {format.names.ed}
-{
-  format.names
-}
-FUNCTION {format.authors}
-{ author "author" format.names
-}
-FUNCTION {get.bbl.editor}
-{ editor num.names$ #1 > 'bbl.editors 'bbl.editor if$ }
-
-FUNCTION {format.editors}
-{ editor "editor" format.names duplicate$ empty$ 'skip$
-    {
-      " " *
-      get.bbl.editor
-   "(" swap$ * ")" *
-      *
-    }
-  if$
-}
-FUNCTION {select.language}
-{ duplicate$ empty$
-    'pop$
-    { language empty$
-        'skip$
-        { "{\selectlanguage{" language * "}" * swap$ * "}" * }
-      if$
-    }
-    if$
-}
-
-FUNCTION {format.note}
-{
- note empty$
-    { "" }
-    { note #1 #1 substring$
-      duplicate$ "{" =
-        'skip$
-        { output.state mid.sentence =
-          { "l" }
-          { "u" }
-        if$
-        change.case$
-        }
-      if$
-      note #2 global.max$ substring$ * "note" bibinfo.check
-    }
-  if$
-}
-
-FUNCTION {format.title}
-{ title
-  duplicate$ empty$ 'skip$
-    { "t" change.case$ }
-  if$
-  "title" bibinfo.check
-  duplicate$ empty$ 'skip$
-    {
-      select.language
-    }
-  if$
-}
-FUNCTION {output.bibitem}
-{ newline$
-  "\bibitem{" write$
-  cite$ write$
-  "}" write$
-  newline$
-  ""
-  before.all 'output.state :=
-}
-
-FUNCTION {n.dashify}
-{
-  't :=
-  ""
-    { t empty$ not }
-    { t #1 #1 substring$ "-" =
-        { t #1 #2 substring$ "--" = not
-            { "--" *
-              t #2 global.max$ substring$ 't :=
-            }
-            {   { t #1 #1 substring$ "-" = }
-                { "-" *
-                  t #2 global.max$ substring$ 't :=
-                }
-              while$
-            }
-          if$
-        }
-        { t #1 #1 substring$ *
-          t #2 global.max$ substring$ 't :=
-        }
-      if$
-    }
-  while$
-}
-
-FUNCTION {word.in}
-{ bbl.in capitalize
-  " " * }
-
-FUNCTION {format.date}
-{
-  month "month" bibinfo.check
-  duplicate$ empty$
-  year  "year"  bibinfo.check duplicate$ empty$
-    { swap$ 'skip$
-        { "there's a month but no year in " cite$ * warning$ }
-      if$
-      *
-    }
-    { swap$ 'skip$
-        {
-          swap$
-          " " * swap$
-        }
-      if$
-      *
-    }
-  if$
-  duplicate$ empty$
-    'skip$
-    {
-      before.all 'output.state :=
-    " (" swap$ * ")" *
-    }
-  if$
-}
-FUNCTION {format.btitle}
-{ title "title" bibinfo.check
-  duplicate$ empty$ 'skip$
-    {
-      emphasize
-      select.language
-    }
-  if$
-}
-FUNCTION {either.or.check}
-{ empty$
-    'pop$
-    { "can't use both " swap$ * " fields in " * cite$ * warning$ }
-  if$
-}
-FUNCTION {format.bvolume}
-{ volume empty$
-    { "" }
-    { bbl.volume volume tie.or.space.prefix
-      "volume" bibinfo.check * *
-      series "series" bibinfo.check
-      duplicate$ empty$ 'pop$
-        { swap$ bbl.of space.word * swap$
-          emphasize * }
-      if$
-      "volume and number" number either.or.check
-    }
-  if$
-}
-FUNCTION {format.number.series}
-{ volume empty$
-    { number empty$
-        { series field.or.null }
-        { series empty$
-            { number "number" bibinfo.check }
-            { output.state mid.sentence =
-                { bbl.number }
-                { bbl.number capitalize }
-              if$
-              number tie.or.space.prefix "number" bibinfo.check * *
-              bbl.in space.word *
-              series "series" bibinfo.check *
-            }
-          if$
-        }
-      if$
-    }
-    { "" }
-  if$
-}
-
-FUNCTION {format.edition}
-{ edition duplicate$ empty$ 'skip$
-    {
-      output.state mid.sentence =
-        { "l" }
-        { "t" }
-      if$ change.case$
-      "edition" bibinfo.check
-      " " * bbl.edition *
-    }
-  if$
-}
-INTEGERS { multiresult }
-FUNCTION {multi.page.check}
-{ 't :=
-  #0 'multiresult :=
-    { multiresult not
-      t empty$ not
-      and
-    }
-    { t #1 #1 substring$
-      duplicate$ "-" =
-      swap$ duplicate$ "," =
-      swap$ "+" =
-      or or
-        { #1 'multiresult := }
-        { t #2 global.max$ substring$ 't := }
-      if$
-    }
-  while$
-  multiresult
-}
-FUNCTION {format.pages}
-{ pages duplicate$ empty$ 'skip$
-    { duplicate$ multi.page.check
-        {
-          bbl.pages swap$
-          n.dashify
-        }
-        {
-          bbl.page swap$
-        }
-      if$
-      tie.or.space.prefix
-      "pages" bibinfo.check
-      * *
-    }
-  if$
-}
-FUNCTION {format.journal.pages}
-{ pages duplicate$ empty$ 'pop$
-    { swap$ duplicate$ empty$
-        { pop$ pop$ format.pages }
-        {
-          ":" *
-          swap$
-          n.dashify
-          pages multi.page.check
-            'bbl.pages
-            'bbl.page
-          if$
-          swap$ tie.or.space.prefix
-          "pages" bibinfo.check
-          * *
-          *
-        }
-      if$
-    }
-  if$
-}
-FUNCTION {format.journal.eid}
-{ eid "eid" bibinfo.check
-  duplicate$ empty$ 'pop$
-    { swap$ duplicate$ empty$ 'skip$
-      {
-          ":" *
-      }
-      if$
-      swap$ *
-    }
-  if$
-}
-FUNCTION {format.vol.num.pages}
-{ volume field.or.null
-  duplicate$ empty$ 'skip$
-    {
-      "volume" bibinfo.check
-    }
-  if$
-  number "number" bibinfo.check duplicate$ empty$ 'skip$
-    {
-      swap$ duplicate$ empty$
-        { "there's a number but no volume in " cite$ * warning$ }
-        'skip$
-      if$
-      swap$
-      "(" swap$ * ")" *
-    }
-  if$ *
-  eid empty$
-    { format.journal.pages }
-    { format.journal.eid }
-  if$
-}
-
-FUNCTION {format.chapter.pages}
-{ chapter empty$
-    'format.pages
-    { type empty$
-        { bbl.chapter }
-        { type "l" change.case$
-          "type" bibinfo.check
-        }
-      if$
-      chapter tie.or.space.prefix
-      "chapter" bibinfo.check
-      * *
-      pages empty$
-        'skip$
-        { ", " * format.pages * }
-      if$
-    }
-  if$
-}
-
-FUNCTION {format.booktitle}
-{
-  booktitle "booktitle" bibinfo.check
-  emphasize
-}
-FUNCTION {format.in.ed.booktitle}
-{ format.booktitle duplicate$ empty$ 'skip$
-    {
-      editor "editor" format.names.ed duplicate$ empty$ 'pop$
-        {
-          " " *
-          get.bbl.editor
-          "(" swap$ * "), " *
-          * swap$
-          * }
-      if$
-      word.in swap$ *
-    }
-  if$
-}
-FUNCTION {empty.misc.check}
-{ author empty$ title empty$ howpublished empty$
-  month empty$ year empty$ note empty$
-  and and and and and
-    { "all relevant fields are empty in " cite$ * warning$ }
-    'skip$
-  if$
-}
-FUNCTION {format.thesis.type}
-{ type duplicate$ empty$
-    'pop$
-    { swap$ pop$
-      "t" change.case$ "type" bibinfo.check
-    }
-  if$
-}
-FUNCTION {format.tr.number}
-{ number "number" bibinfo.check
-  type duplicate$ empty$
-    { pop$ bbl.techrep }
-    'skip$
-  if$
-  "type" bibinfo.check
-  swap$ duplicate$ empty$
-    { pop$ "t" change.case$ }
-    { tie.or.space.prefix * * }
-  if$
-}
-FUNCTION {format.article.crossref}
-{
-  key duplicate$ empty$
-    { pop$
-      journal duplicate$ empty$
-        { "need key or journal for " cite$ * " to crossref " * crossref * warning$ }
-        { "journal" bibinfo.check emphasize word.in swap$ * }
-      if$
-    }
-    { word.in swap$ * " " *}
-  if$
-  " \cite{" * crossref * "}" *
-}
-FUNCTION {format.crossref.editor}
-{ editor #1 "{vv~}{ll}" format.name$
-  "editor" bibinfo.check
-  editor num.names$ duplicate$
-  #2 >
-    { pop$
-      "editor" bibinfo.check
-      " " * bbl.etal
-      emphasize
-      *
-    }
-    { #2 <
-        'skip$
-        { editor #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
-            {
-              "editor" bibinfo.check
-              " " * bbl.etal
-              emphasize
-              *
-            }
-            {
-             bbl.and space.word
-              * editor #2 "{vv~}{ll}" format.name$
-              "editor" bibinfo.check
-              *
-            }
-          if$
-        }
-      if$
-    }
-  if$
-}
-FUNCTION {format.book.crossref}
-{ volume duplicate$ empty$
-    { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
-      pop$ word.in
-    }
-    { bbl.volume
-      capitalize
-      swap$ tie.or.space.prefix "volume" bibinfo.check * * bbl.of space.word *
-    }
-  if$
-  editor empty$
-  editor field.or.null author field.or.null =
-  or
-    { key empty$
-        { series empty$
-            { "need editor, key, or series for " cite$ * " to crossref " *
-              crossref * warning$
-              "" *
-            }
-            { series emphasize * }
-          if$
-        }
-        { key * }
-      if$
-    }
-    { format.crossref.editor * }
-  if$
-  " \cite{" * crossref * "}" *
-}
-FUNCTION {format.incoll.inproc.crossref}
-{
-  editor empty$
-  editor field.or.null author field.or.null =
-  or
-    { key empty$
-        { format.booktitle duplicate$ empty$
-            { "need editor, key, or booktitle for " cite$ * " to crossref " *
-              crossref * warning$
-            }
-            { word.in swap$ * }
-          if$
-        }
-        { word.in key * " " *}
-      if$
-    }
-    { word.in format.crossref.editor * " " *}
-  if$
-  " \cite{" * crossref * "}" *
-}
-FUNCTION {format.org.or.pub}
-{ 't :=
-  ""
-  address empty$ t empty$ and
-    'skip$
-    {
-      t empty$
-        { address "address" bibinfo.check *
-        }
-        { t *
-          address empty$
-            'skip$
-            { ", " * address "address" bibinfo.check * }
-          if$
-        }
-      if$
-    }
-  if$
-}
-FUNCTION {format.publisher.address}
-{ publisher "publisher" bibinfo.warn format.org.or.pub
-}
-
-FUNCTION {format.organization.address}
-{ organization "organization" bibinfo.check format.org.or.pub
-}
-
-FUNCTION {article}
-{ output.bibitem
-  format.authors "author" output.check
-  new.block
-  format.title "title" output.check
-  new.block
-  crossref missing$
-    {
-      journal
-      "journal" bibinfo.check
-      emphasize
-      "journal" output.check
-      format.vol.num.pages output
-      format.date "year" output.check
-    }
-    { format.article.crossref output.nonnull
-      format.pages output
-    }
-  if$
-  new.block
-  format.url output
-  new.block
-  format.note output
-  fin.entry
-}
-FUNCTION {book}
-{ output.bibitem
-  author empty$
-    { format.editors "author and editor" output.check
-    }
-    { format.authors output.nonnull
-      crossref missing$
-        { "author and editor" editor either.or.check }
-        'skip$
-      if$
-    }
-  if$
-  new.block
-  format.btitle "title" output.check
-  crossref missing$
-    { format.bvolume output
-      new.block
-      new.sentence
-      format.number.series output
-      format.publisher.address output
-    }
-    {
-      new.block
-      format.book.crossref output.nonnull
-    }
-  if$
-  format.edition output
-  format.date "year" output.check
-  new.block
-  format.url output
-  new.block
-  format.note output
-  fin.entry
-}
-FUNCTION {booklet}
-{ output.bibitem
-  format.authors output
-  new.block
-  format.title "title" output.check
-  new.block
-  howpublished "howpublished" bibinfo.check output
-  address "address" bibinfo.check output
-  format.date output
-  new.block
-  format.url output
-  new.block
-  format.note output
-  fin.entry
-}
-
-FUNCTION {inbook}
-{ output.bibitem
-  author empty$
-    { format.editors "author and editor" output.check
-    }
-    { format.authors output.nonnull
-      crossref missing$
-        { "author and editor" editor either.or.check }
-        'skip$
-      if$
-    }
-  if$
-  new.block
-  format.btitle "title" output.check
-  crossref missing$
-    {
-      format.bvolume output
-      format.chapter.pages "chapter and pages" output.check
-      new.block
-      new.sentence
-      format.number.series output
-      format.publisher.address output
-    }
-    {
-      format.chapter.pages "chapter and pages" output.check
-      new.block
-      format.book.crossref output.nonnull
-    }
-  if$
-  format.edition output
-  format.date "year" output.check
-  new.block
-  format.url output
-  new.block
-  format.note output
-  fin.entry
-}
-
-FUNCTION {incollection}
-{ output.bibitem
-  format.authors "author" output.check
-  new.block
-  format.title "title" output.check
-  new.block
-  crossref missing$
-    { format.in.ed.booktitle "booktitle" output.check
-      format.bvolume output
-      format.chapter.pages output
-      new.sentence
-      format.number.series output
-      format.publisher.address output
-      format.edition output
-      format.date "year" output.check
-    }
-    { format.incoll.inproc.crossref output.nonnull
-      format.chapter.pages output
-    }
-  if$
-  new.block
-  format.url output
-  new.block
-  format.note output
-  fin.entry
-}
-FUNCTION {inproceedings}
-{ output.bibitem
-  format.authors "author" output.check
-  new.block
-  format.title "title" output.check
-  new.block
-  crossref missing$
-    { format.in.ed.booktitle "booktitle" output.check
-      format.bvolume output
-      format.pages output
-      new.sentence
-      format.number.series output
-      publisher empty$
-        { format.organization.address output }
-        { organization "organization" bibinfo.check output
-          format.publisher.address output
-        }
-      if$
-      format.date "year" output.check
-    }
-    { format.incoll.inproc.crossref output.nonnull
-      format.pages output
-    }
-  if$
-  new.block
-  format.url output
-  new.block
-  format.note output
-  fin.entry
-}
-FUNCTION {conference} { inproceedings }
-FUNCTION {manual}
-{ output.bibitem
-  author empty$
-    { organization "organization" bibinfo.check
-      duplicate$ empty$ 'pop$
-        { output
-          address "address" bibinfo.check output
-        }
-      if$
-    }
-    { format.authors output.nonnull }
-  if$
-  new.block
-  format.btitle "title" output.check
-  author empty$
-    { organization empty$
-        {
-          address new.block.checka
-          address "address" bibinfo.check output
-        }
-        'skip$
-      if$
-    }
-    {
-      organization address new.block.checkb
-      organization "organization" bibinfo.check output
-      address "address" bibinfo.check output
-    }
-  if$
-  format.edition output
-  format.date output
-  new.block
-  format.url output
-  new.block
-  format.note output
-  fin.entry
-}
-
-FUNCTION {mastersthesis}
-{ output.bibitem
-  format.authors "author" output.check
-  new.block
-  format.btitle
-  "title" output.check
-  new.block
-  bbl.mthesis format.thesis.type output.nonnull
-  school "school" bibinfo.warn output
-  address "address" bibinfo.check output
-  format.date "year" output.check
-  new.block
-  format.url output
-  new.block
-  format.note output
-  fin.entry
-}
-
-FUNCTION {misc}
-{ output.bibitem
-  format.authors output
-  title howpublished new.block.checkb
-  format.title output
-  howpublished new.block.checka
-  howpublished "howpublished" bibinfo.check output
-  format.date output
-  new.block
-  format.url output
-  new.block
-  format.note output
-  fin.entry
-  empty.misc.check
-}
-FUNCTION {phdthesis}
-{ output.bibitem
-  format.authors "author" output.check
-  new.block
-  format.btitle
-  "title" output.check
-  new.block
-  bbl.phdthesis format.thesis.type output.nonnull
-  school "school" bibinfo.warn output
-  address "address" bibinfo.check output
-  format.date "year" output.check
-  new.block
-  format.url output
-  new.block
-  format.note output
-  fin.entry
-}
-
-FUNCTION {proceedings}
-{ output.bibitem
-  editor empty$
-    { organization "organization" bibinfo.check output
-    }
-    { format.editors output.nonnull }
-  if$
-  new.block
-  format.btitle "title" output.check
-  format.bvolume output
-  editor empty$
-    { publisher empty$
-        'skip$
-        {
-          new.sentence
-          format.number.series output
-          format.publisher.address output
-        }
-      if$
-    }
-    { publisher empty$
-        {
-          new.sentence
-          format.organization.address output }
-        {
-          new.sentence
-          organization "organization" bibinfo.check output
-          format.publisher.address output
-        }
-      if$
-     }
-  if$
-      format.date "year" output.check
-  new.block
-  format.url output
-  new.block
-  format.note output
-  fin.entry
-}
-
-FUNCTION {techreport}
-{ output.bibitem
-  format.authors "author" output.check
-  new.block
-  format.title
-  "title" output.check
-  new.block
-  format.tr.number output.nonnull
-  institution "institution" bibinfo.warn output
-  address "address" bibinfo.check output
-  format.date "year" output.check
-  new.block
-  format.url output
-  new.block
-  format.note output
-  fin.entry
-}
-
-FUNCTION {unpublished}
-{ output.bibitem
-  format.authors "author" output.check
-  new.block
-  format.title "title" output.check
-  format.date output
-  new.block
-  format.url output
-  new.block
-  format.note "note" output.check
-  fin.entry
-}
-
-FUNCTION {default.type} { misc }
-READ
-STRINGS { longest.label }
-INTEGERS { number.label longest.label.width }
-FUNCTION {initialize.longest.label}
-{ "" 'longest.label :=
-  #1 'number.label :=
-  #0 'longest.label.width :=
-}
-FUNCTION {longest.label.pass}
-{ number.label int.to.str$ 'label :=
-  number.label #1 + 'number.label :=
-  label width$ longest.label.width >
-    { label 'longest.label :=
-      label width$ 'longest.label.width :=
-    }
-    'skip$
-  if$
-}
-EXECUTE {initialize.longest.label}
-ITERATE {longest.label.pass}
-FUNCTION {begin.bib}
-{ preamble$ empty$
-    'skip$
-    { preamble$ write$ newline$ }
-  if$
-  "\begin{thebibliography}{"  longest.label  * "}" *
-  write$ newline$
-  "\providecommand{\url}[1]{\texttt{#1}}"
-  write$ newline$
-  "\providecommand{\urlprefix}{URL }"
-  write$ newline$
-  "\providecommand{\selectlanguage}[1]{\relax}"
-  write$ newline$
-}
-EXECUTE {begin.bib}
-EXECUTE {init.state.consts}
-ITERATE {call.type$}
-FUNCTION {end.bib}
-{ newline$
-  "\end{thebibliography}" write$ newline$
-}
-EXECUTE {end.bib}
-%% End of customized bst file
-%%
-%% End of file `tmr.bst'.
diff --git a/doc/tmr.cls b/doc/tmr.cls
deleted file mode 100644
--- a/doc/tmr.cls
+++ /dev/null
@@ -1,381 +0,0 @@
-\ProvidesClass{tmr}
-\LoadClass[12pt,twoside,DIV10]{scrreprt}
-
-\RequirePackage{scrpage2}
-\RequirePackage{relsize}
-\RequirePackage[colorlinks=true,
-                linkcolor=black,
-                urlcolor=black,
-                citecolor=black]{hyperref}
-\RequirePackage{ae}
-\RequirePackage{paralist}
-\RequirePackage{amsthm}
-\RequirePackage{amssymb}
-\RequirePackage{graphicx}
-
-% title
-\global\let\@authors\@empty
-\global\let\email\@gobble
-
-\newif\ifcomplete
-\newif\iftikz
-
-\DeclareOption{complete}{\completetrue}
-\DeclareOption{secheadings}{\AtBeginDocument{\setcounter{tocdepth}{1}}}
-\DeclareOption{tikz}{\tikztrue}
-\AtBeginDocument{\setcounter{tocdepth}{0}}
-\ProcessOptions
-
-\ifcomplete
-  \RequirePackage{multibbl}
-  \title{The Monad.Reader\@issue}
-\fi
-
-\iftikz
-  \RequirePackage{tikz}
-\fi
-
-\let\@issue\empty
-\def\issue#1{\gdef\@issue{ #1}}%
-
-\renewcommand\titlepagestyle{empty}
-
-\renewcommand*\maketitle{\par
-       \ifcomplete
-         \@ifundefined{@firsttitle}{%
-           \dedication{\vspace*{0.2cm}\begin{center}\tmrlogo\end{center}\vspace*{0.5cm}}}{}%
-       \fi
-       \begingroup
-         \renewcommand*\thefootnote{\@fnsymbol\c@footnote}%
-         \let\@oldmakefnmark\@makefnmark
-         \def\@makefnmark{\rlap\@oldmakefnmark}
-         \newpage
-         \global\@topnum\z@   % Prevents figures from going at top of page.
-         \@maketitle
-         \thispagestyle{\titlepagestyle}\@thanks
-       \endgroup
-       \setcounter{footnote}{0}%
-       \ifcomplete
-         \@ifundefined{@firsttitle}{%
-           \@namedef{@firsttitle}{}}{%
-           \refstepcounter{chapter}%
-           % wild hack to get a reasonable entry for the TOC, including author and title
-           \addcontentsline{toc}{chapter}{{\normalfont \@author}\texorpdfstring{\\ \leavevmode\hspace*{-\leftskip}}{: }\@title}}%
-       \fi
-       \let\thanks\relax
-       %\let\maketitle\relax
-       %\let\@maketitle\relax
-       \global\let\@thanks\@empty
-       %\global\let\@author\@empty
-       \global\let\@date\@empty
-       %\global\let\@title\@empty
-       \global\let\@extratitle\@empty
-       \global\let\@titlehead\@empty
-       \global\let\@subject\@empty
-       \global\let\@publishers\@empty
-       \global\let\@uppertitleback\@empty
-       \global\let\@lowertitleback\@empty
-       \global\let\@dedication\@empty
-       \ifcomplete\else
-         \global\let\author\relax
-         \global\let\title\relax
-         \global\let\extratitle\relax
-         \global\let\titlehead\relax
-         \global\let\subject\relax
-         \global\let\publishers\relax
-         \global\let\uppertitleback\relax
-         \global\let\lowertitleback\relax
-         \global\let\dedication\relax
-         \global\let\date\relax
-         \global\let\and\relax
-       \fi}
-
-\def\author#1{%
-    %\message{author called: #1.}%
-    \def\@cauthor{#1}%
-    \if\@cauthor\@empty
-      \global\let\@author\@empty
-      \global\let\@authors\@empty
-    \else
-      \ifx\@authors\@empty
-        \gdef\@author{#1}%
-        \gdef\@authors{by #1}%
-      \else
-        \g@addto@macro\@author{, #1}%
-        \g@addto@macro\@authors{\\ and #1}%
-      \fi
-    \fi}
-
-\def\@maketitle{%
-    \clearpage
-    \let\footnote\thanks
-    \ifx\@extratitle\@empty \else
-        \noindent\@extratitle \next@tpage \if@twoside \null\next@tpage \fi
-    \fi
-    \ifx\@titlehead\@empty \else
-        \noindent\begin{minipage}[t]{\textwidth}
-        \@titlehead
-        \end{minipage}\par
-    \fi
-    \null
-    \vskip 4em%
-    \begin{flushleft}%
-    \ifx\@subject\@empty \else
-        {\Large \@subject \par}
-        \vskip 1.5em
-    \fi
-    {\sectfont\Huge \@title \par}%
-    \vskip 1.5em%
-    {\large
-      \lineskip .5em%
-      \sffamily 
-      \def\email##1{{\ \smaller$\langle$##1$\rangle$}}%
-      \begin{tabular}[t]{@{}l@{}}%
-        \@authors
-      \end{tabular}\par}%
-    \vskip 1em%
-    {\large\sffamily \@date \par}%
-    \vskip \z@ \@plus 1em
-    \ifx\@dedication\@empty \else
-        \vskip 2em
-        {\Large \@dedication \par}
-    \fi
-    {\Large\sffamily \@publishers \par}
-  \end{flushleft}%
-  \par
-  \vskip 2em}
-
-\setcounter{secnumdepth}{-1}
-
-\AtBeginDocument{\@@maketitle}
-\ifcomplete
-  \AtBeginDocument{\musthavepagestyle{empty}}
-\fi
-
-\def\tmrlogo{\includegraphics[scale=0.6]{tmr_logo.pdf}}
-
-% page style
-
-\pagestyle{scrheadings}
-\lehead{\small\normalfont\TMR\@issue}
-\rohead{\small\normalfont\@author: \@title}
-\ofoot[\small\pagemark]{\small\pagemark}
-
-% counters
-
-\renewcommand{\thefigure}{\arabic{figure}}
-
-% fonts
-
-\renewcommand{\bfdefault}{b}
-\DeclareRobustCommand\em{\@nomath\em\bfseries}
-
-% introduction environment
-
-\newenvironment{introduction}
-  {\normalfont\itshape\noindent\ignorespaces}
-  {\ignorespacesafterend}
-
-% math
-
-\RequirePackage{amsmath}
-\numberwithin{equation}{chapter}
-\renewcommand{\theequation}{\arabic{equation}}
-
-% floats
-
-\RequirePackage{float}
-\newcommand{\fs@tmr}{%
-  \def\@fs@cfont{\sectfont}%
-  \def\@fs@capt{\floatc@plain}%
-  \def\@fs@pre{\hrule\kern12pt}%
-    %\color{lightgray}%
-    %\setbox\@currbox\vbox{\hbadness10000
-    %\moveleft3.4pt\vbox{\advance\hsize by6.8pt%
-    %\hrule\hbox to\hsize{\vrule\kern3pt
-    %\vbox{\kern3pt\box\@currbox\kern3pt}\kern3pt
-    %\color{lightgray}\vrule}\color{lightgray}\hrule}}}%
-  \def\@fs@mid{\hrule\kern7pt}%
-  \def\@fs@post{}\let\@fs@iftopcapt\iffalse}
-\floatstyle{tmr}
-\floatplacement{figure}{htbp}
-\restylefloat{figure}
-\floatplacement{table}{htbp}
-\restylefloat{table}
-\newfloat{listing}{htbp}{ltg}
-\floatname{listing}{Listing}
-
-% verbatim
-
-\RequirePackage{fancyvrb}
-%\DefineShortVerb{\|}
-\AtBeginDocument{\VerbatimFootnotes}
-
-% verbatim requires a workaround for tabulars
-\let\tmr@tabular\tabular
-\let\tmr@endtabular\endtabular
-\def\tabular{\UndefineShortVerb{\|}\tmr@tabular}
-\def\endtabular{\tmr@endtabular\DefineShortVerb{\|}}
-
-% blocks
-\thm@headfont{\sectfont}
-\theoremstyle{plain}
-\newtheorem{theorem}{Theorem}
-\let\amsnewtheorem\newtheorem
-\def\newtheorem#1{\amsnewtheorem{#1}[theorem]}
-
-\newtheorem{lemma}{Lemma}
-\newtheorem{corollary}{Corollary}
-
-\theoremstyle{definition}
-
-\newtheorem{definition}{Definition}
-\newtheorem{remark}{Remark}
-\newtheorem{example}{Example}
-\newtheorem{exercise}{Exercise}
-
-% TMR logo
-
-\def\TMR{{\normalfont\sffamily The Monad.Reader}}
-
-% Itemize / Enumerate
-
-\renewcommand{\labelitemi}{\raisebox{1.3pt}{\footnotesize$\blacktriangleright$}}
-\renewcommand{\labelitemii}{$\bullet$}
-\renewcommand{\labelitemiii}{$\circ$}
-
-\let\longitem\itemize
-\let\endlongitem\enditemize
-\let\longenum\enumerate
-\let\endlongenum\endenumerate
-\let\itemize\compactitem
-\let\enditemize\endcompactitem
-\let\enumerate\compactenum
-\let\endenumerate\endcompactenum
-
-% Bibliography
-\ifcomplete\else
-  \bibliographystyle{tmr}
-\fi
-\def\urlprefix{}
-
-\newcommand*\refname{References}
-\renewcommand*\bib@heading{\section*{\refname}\small}
-
-% Discouraging all sorts of commands
-
-\let\musthavefootnote\footnote
-\def\footnote{%
-  \ClassError{tmr}%
-    {footnote should not be used}%
-    {The TMR style guidelines say that footnotes should be avoided
-     if at all possible. If you absolutely need one, use
-     \string\musthavefootnote\space instead.}}
-
-\def\abstract{%
-  \ClassError{tmr}%
-    {abstract is not available}%
-    {There should be no abstract for TMR articles. Instead, a short
-     introduction can be given using the introduction environment.}
-  \introduction}
-
-\let\endabstract\endintroduction
-
-\let\@@maketitle\maketitle
-\def\maketitle{%
-  \ClassError{tmr}%
-    {maketitle is not needed}%
-    {The TMR class automatically inserts the title if you set
-     use \string\title\space and \string\author\space in the document preamble.}}
-
-\let\musthavesubsubsection\subsubsection
-\def\subsubsection{%
-  \ClassError{tmr}%
-    {subsubsection should not be used}%
-    {The TMR style guidelines ask you to use only two sectioning
-     levels. If you absolutely need this, use
-     \string\musthavesubsubsection\space or
-     \string\paragraph\space instead.}%
-  \musthavesubsubsection}
-
-\let\subparagraph\undefined
-
-\let\musthavepagestyle\pagestyle
-\def\pagestyle{%
-  \ClassError{tmr}%
-    {please do not change the pagestyle}%
-    {The TMR style guidelines ask you to touch the default pagestyle.
-     If you absolutely must do it, use
-     \string\musthavepagestyle\space instead.}}
-
-% For the complete magazine
-
-\setcounter{tocdepth}{2}
-
-\let\@@pkgextension\@pkgextension
-\let\@@ifl@aded\@ifl@aded
-
-\def\article#1{%
-  \begingroup
-  \cleardoublepage
-  \musthavepagestyle{scrheadings}%
-  \global\let\@author\@empty
-  \global\let\@title\@empty
-  \global\let\@cauthor\@empty
-  \global\let\@authors\@empty
-  \newbibliography{#1}%
-  \bibliographystyle{#1}{tmr}%
-  \let\tmr@cite\cite
-  \let\tmr@bibliography\bibliography
-  \renewcommand\cite[2][]{%
-     \def\tmr@temp{##1}%
-     \ifx\tmr@temp\empty
-       \def\tmr@temp{\tmr@cite{#1}{##2}}%
-     \else
-       \def\tmr@temp{\tmr@cite[##1]{#1}{##2}}%
-     \fi\tmr@temp}
-  \renewcommand\bibliography[1]{\tmr@bibliography{#1}{##1}{References}}%
-  \renewcommand\documentclass[2][]{}%
-%  \def\usepackage{\@ifnextchar[\@checkpackages{\@checkpackages[]}}
-  \renewcommand\usepackage[2][]{\@checkpackages{##2}}%
-  \def\document{\@@maketitle}\let\enddocument\empty
-  \input{#1}%
-  \endgroup
-}
-
-% fix bug in multibbl
-\ifcomplete
-  \def\@citex[#1]#2#3{%
-    \let\@citea\@empty
-    \@cite{\@for\@citeb:=#3\do
-      {\@citea\def\@citea{,\penalty\@m\ }%
-       \edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
-       \@ifundefined{#2@auxfile}{}{\expandafter\immediate%
-          \write\csname #2@auxfile\endcsname{\string\citation{\@citeb}}}%
-       \@ifundefined{b@\@citeb}{\mbox{\reset@font\bfseries ?}%
-         \G@refundefinedtrue
-         \@latex@warning
-           {Citation `\@citeb' on page \thepage \space undefined}}%
-         {\hbox{\csname b@\@citeb\endcsname}}}}{#1}}
-\fi
-
-\def\@checkpackages#1{%
-  \def\reserved@b##1,{%
-      \ifx\@nil##1\relax\else
-        \ifx\relax##1\relax\else
-         \noexpand\@checkpackage##1[]%\noexpand\@@pkgextension
-        \fi
-        \expandafter\reserved@b
-      \fi}%
-      \edef\reserved@a{\zap@space#1 \@empty}%
-      \edef\reserved@a{\expandafter\reserved@b\reserved@a,\@nil,}%
-  \reserved@a}
-
-\def\@checkpackage#1[]{%
-  \@@ifl@aded\@@pkgextension{#1}{}{
-    \ClassError{tmr}%
-      {package #1 not loaded}%
-      {Package #1 is required by an article, but has not been loaded in the
-       preamble.}}}
-
-
diff --git a/doc/tmr.dbj b/doc/tmr.dbj
deleted file mode 100644
--- a/doc/tmr.dbj
+++ /dev/null
@@ -1,520 +0,0 @@
-%% Driver file to produce tmr.bst from merlin.mbs
-%% Generated with makebst, version 4.1 (2003/09/08)
-%% Produced on 2005/02/15 at 20:47
-%% 
-\input docstrip
-
-\preamble
-----------------------------------------
-*** bibliography style for The Monad.Reader ***
-
-\endpreamble
-
-\postamble
-End of customized bst file
-\endpostamble
-
-\keepsilent
-
-\askforoverwritefalse
-\def\MBopts{\from{merlin.mbs}{%
-%EXTERNAL FILES:
-%Name of language file: \cfile=.
-%No included files.
-%INTERNAL LANGUAGE SUPPORT (if no external language file)
-    %: (def) English
-% babel,%: Babel
-%--------------------
-%STYLE OF CITATIONS:
-    %: (def) Numerical
-% ay,%: Author-year
-% alph,%: Alpha style, Jon90 or JWB90
-% alph,alf-1,%: Alpha style, Jon90
-% alph,alf-f,%: Alpha style, Jones90
-% cite,%: Cite key
-%--------------------
-%HTML OUTPUT (if non author-year citations)
-    %: (def) Normal LaTeX
-% html,%: Hypertext
-% html,htlist,%: Hypertext list
-% html,htdes,%: Hypertext with keys
-%--------------------
-%AUTHOR--YEAR SUPPORT SYSTEM (if author-year citations)
-% nat,%: Natbib
-%   %: (def) Older Natbib
-% alk,%: Apalike
-% har,%: Harvard
-% ast,%: Astronomy
-% cay,%: Chicago
-% nmd,%: Named
-% cn,%: Author-date
-%--------------------
-%HARVARD EXTENSIONS INCLUDED (if Harvard support selected)
-% harnm,%: With Harvard extensions
-%   %: (def) Older Harvard
-%--------------------
-%LANGUAGE FIELD
-%   %: (def) No language field
-  lang,%: Add language field
-%--------------------
-%ANNOTATIONS:
-    %: (def) No annotations
-% annote,%: Annotations
-%--------------------
-%ORDERING OF REFERENCES (if non-author/year and non-alph)
-%   %: (def) Alphabetical
-  seq-no,%: Citation order
-% seq-yr,%: Year ordered
-% seq-yrr,%: Reverse year ordered
-%--------------------
-%ORDERING OF REFERENCES (if author-year citations)
-%   %: (def) Alphabetical
-% seq-lab,%: By label
-% seq-key,%: By label and cite key
-% seq-yr,%: Year ordered
-% seq-yrr,%: Reverse year ordered
-% seq-no,%: Citation order
-%--------------------
-%ORDER ON VON PART (if not citation order)
-    %: (def) Sort on von part
-% vonx,%: Sort without von part
-%--------------------
-%AUTHOR NAMES:
-  ed-au,%: Full, surname last
-% nm-revf,%: Full, surname first
-% nm-init,ed-au,%: Initials + surname
-% nm-rev,%: Surname + initials
-% nm-rv,%: Surname + dotless initials
-% nm-rvx,%: Surname + pure initials
-% nm-rvv,%: Surname + spaceless initials
-% nm-rev1,%: Only first name reversed, initials
-% nm-revv1,%: First name reversed, with full names
-%--------------------
-%EDITOR NAMES IN COLLECTIONS (if author names reversed)
-% ed-rev,%: Editor names reversed
-%--------------------
-%POSITION OF JUNIOR (if author names reversed)
-% jnrlst,%: Junior comes last
-%   %: (def) Junior between
-%--------------------
-%JUNIOR PART IN THE CITATION (if author-year citations)
-%   %: (def) No `junior' part in the citations
-% jnrlab,%: `Junior' in citations
-%--------------------
-%PUNCTUATION BETWEEN AUTHOR NAMES:
-    %: (def) Author names separated by commas
-% aunm-semi,%: Names separated by semi-colon
-% aunm-sl,%: Names separated by slash
-%--------------------
-%ADJACENT REFERENCES WITH REPEATED NAMES:
-    %: (def) Author/editor names always present
-% nmdash,%: Repeated author/editor names replaced by dash
-% nmdash,nmd-2,%: Repeated author/editor names replaced by 2 dashes
-% nmdash,nmd-3,%: Repeated author/editor names replaced by 3 dashes
-%--------------------
-%NUMBER OF AUTHORS:
-    %: (def) All authors
-% nmlm,%: Limited authors
-%--------------------
-%TYPEFACE FOR AUTHORS IN LIST OF REFERENCES:
-    %: (def) Normal font for author names
-% nmft,nmft-sc,%: Small caps authors
-% nmft,nmft-it,%: Italic authors
-% nmft,nmft-bf,%: Bold authors
-% nmft,nmft-def,%: User defined author font
-%--------------------
-%FONT FOR FIRST NAMES (if non-default font for authors)
-%   %: (def) First names same font as surnames
-% fnm-rm,%: First names in normal font
-% fnm-def,%: First names in user defined font
-%--------------------
-%EDITOR NAMES IN INCOLLECTION ETC:
-%   %: (def) Editors incollection normal font
-% nmfted,%: Editors incollection like authors
-%--------------------
-%FONT FOR `AND' IN LIST:
-%   %: (def) `And' in author font
-% nmand-rm,%: `And' in normal font
-%--------------------
-%FONT OF CITATION LABELS IN TEXT (if author-year citations)
-%   %: (def) Cited authors plain
-% lab,lab-it,%: Cited authors italic
-% lab,lab-sc,%: Cited authors small caps
-% lab,lab-bf,%: Cited authors bold
-% lab,lab-def,%: User defined citation font
-%--------------------
-%FONT FOR `AND' IN CITATIONS (if non-default font for citation lables)
-%   %: (def) Cited `and' in author font
-% and-rm,%: Cited `and' in normal font
-%--------------------
-%FONT OF EXTRA LABEL (The extra letter on the year)
-%   %: (def) Extra label plain
-% xlab-it,%: Extra label italic
-%--------------------
-%LABEL WHEN AUTHORS MISSING (if author-year citations)
-% keyxyr,%: Year blank when KEY replaces missing author
-%   %: (def) Year included when KEY replaces missing author
-%--------------------
-%MISSING DATE (if author-year citations)
-%   %: (def) Missing date set to ????
-% blkyear,%: Missing date left blank
-%--------------------
-%DATE POSITION:
-    %: (def) Date at end
-% dt-beg,%: Date after authors
-% dt-jnl,%: Date part of journal spec.
-% dt-end,%: Date at very end
-%--------------------
-%DATE FORMAT (if non author-year citations)
-%   %: (def) Plain month and year
-  yr-par,%: Date in parentheses
-% yr-brk,%: Date in brackets
-% yr-col,%: Date preceded by colon
-% yr-per,%: Date preceded by period
-% yr-com,%: Date preceded by comma
-% yr-blk,%: Date preceded by space
-%--------------------
-%SUPPRESS MONTH:
-    %: (def) Date is month and year
-% xmth,%: Date is year only
-%--------------------
-%REVERSED DATE (if including month)
-    %: (def) Date as month year
-% dtrev,%: Date as year month
-%--------------------
-%DATE FORMAT (if author-year citations)
-%   %: (def) Year plain
-% yr-par,%: Year in parentheses
-% yr-brk,%: Year in brackets
-% yr-col,%: Year preceded by colon
-% yr-per,%: Year preceded by period
-% yr-com,%: Date preceded by comma
-% yr-blk,%: Year preceded by space
-%--------------------
-%INCLUDE MONTHS:
-%   %: (def) Date is year only
-% aymth,%: Include month in date
-%--------------------
-%REVERSED DATE (if including month)
-%   %: (def) Date as month year
-% dtrev,%: Date as year month
-%--------------------
-%DATE PUNCTUATION (if date not at end)
-%   %: (def) Date with standard block punctuation
-% yrp-col,%: Colon after date
-% yrp-semi,%: Semi-colon after date
-% yrp-per,%: Period after date
-% yrp-x,%: No punct. after date
-%--------------------
-%BLANK AFTER DATE:
-%   %: (def) Space after date
-% yrpp-xsp,%: No space after date
-%--------------------
-%DATE FONT:
-    %: (def) Date in normal font
-% dtbf,%: Date in bold face
-%--------------------
-%TRUNCATE YEAR (if author-year citations)
-% note-yr,%: Year text full
-%   %: (def) Year truncated
-%--------------------
-%TITLE OF ARTICLE:
-    %: (def) Title plain
-% tit-it,%: Title italic
-% tit-qq,qt-s,%: Title and punctuation in single quotes
-% tit-qq,%: Title and punctuation in double quotes
-% tit-qq,qt-g,%: Title and punctuation in guillemets
-% tit-qq,qt-s,qx,%: Title in single quotes
-% tit-qq,qx,%: Title in double quotes
-% tit-qq,qt-g,qx,%: Title in guillemets
-%--------------------
-%COLLECTION/PROCEEDINGS TITLES (if quoted title)
-% bt-qq,%: Quote collection and proceedings titles
-%   %: (def) Collection and proceedings titles not in quotes
-%--------------------
-%CAPITALIZATION OF ARTICLE TITLE:
-    %: (def) Sentence style
-% atit-u,%: Title style
-%--------------------
-%ARTICLE TITLE PRESENT:
-    %: (def) Article title present
-% jtit-x,%: No article title
-%--------------------
-%JOURNAL NAMES:
-    %: (def) Periods in journal names
-% jxper,%: Dotless journal names
-%--------------------
-%JOURNAL NAME FONT:
-    %: (def) Journal name italics
-% jttl-rm,%: Journal name normal
-%--------------------
-%THESIS TITLE:
-    %: (def) Thesis titles like books
-% thtit-a,%: Thesis title like article
-% thtit-x,%: No thesis title
-%--------------------
-%TECHNICAL REPORT TITLE:
-    %: (def) Tech. report title like articles
-% trtit-b,%: Tech. report title like books
-%--------------------
-%TECHNICAL REPORT NUMBER:
-    %: (def) Tech. report and number plain
-% trnum-it,%: Tech. report and number italic
-%--------------------
-%JOURNAL VOLUME:
-    %: (def) Volume plain
-% vol-it,%: Volume italic
-% vol-bf,%: Volume bold
-% vol-2bf,%: Volume and number bold
-%--------------------
-%JOURNAL VOL AND NUMBER:
-    %: (def) Journal vol(num)
-% vnum-sp,%: Journal vol (num)
-% vnum-cm,%: Journal vol, num
-% vnum-nr,%: Journal vol, no. num
-% vnum-h,%: Journal vol, \# number
-% vnum-b,%: Journal vol number
-% vnum-x,%: Journal vol, without number
-%--------------------
-%VOLUME PUNCTUATION:
-    %: (def) Volume with colon
-% volp-sp,%: Volume with colon and space
-% volp-semi,%: Volume with semi-colon
-% volp-com,%: Volume with comma
-% volp-blk,%: Volume with blank
-%--------------------
-%YEAR IN JOURNAL SPECIFICATION:
-    %: (def) Journal year like others
-% jdt-v,%: Journal vol(year)
-% jdt-vs,%: Journal vol (year)
-% jdt-p,%: Year with pages
-% jdt-pc,%: Year, comma, pages
-%--------------------
-%PAGE NUMBERS:
-    %: (def) Start and stop page numbers
-% jpg-1,%: Only start page number
-%--------------------
-%LARGE PAGE NUMBERS:
-    %: (def) No separators for large page numbers
-% pgsep-c,%: Comma inserted over 9999
-% pgsep-s,%: Thin space inserted over 9999
-% pgsep-p,%: Period inserted over 9999
-%--------------------
-%WORD `PAGE' IN ARTICLES:
-%   %: (def) Article pages numbers only
-  jwdpg,%: Include `page' in articles
-%--------------------
-%POSITION OF PAGES:
-    %: (def) Pages given mid text
-% pp-last,%: Pages at end
-%--------------------
-%WORD `VOLUME' IN ARTICLES:
-    %: (def) Article volume as number only
-% jwdvol,%: Include `volume' in articles
-%--------------------
-%NUMBER AND SERIES FOR COLLECTIONS:
-  num-xser,%: Allows number without series
-%   %: (def) Standard BibTeX
-%--------------------
-%POSITION OF NUMBER AND SERIES:
-%   %: (def) After chapter and pages
-  numser,%: Just before publisher
-%--------------------
-%VOLUME AND SERIES FOR BOOKS/COLLECTIONS:
-    %: (def) Vol. 23 of Series
-% ser-vol,%: Series, vol. 23
-%--------------------
-%POSITION OF VOLUME AND SERIES FOR INCOLLECTIONS:
-    %: (def) Series and volume after the editors
-% ser-ed,%: Series and volume after booktitle
-%--------------------
-%JOURNAL NAME PUNCTUATION:
-    %: (def) Comma after journal
-% jnm-x,%: Space after journal
-%--------------------
-%BOOK TITLE:
-    %: (def) Book title italic
-% btit-rm,bt-rm,%: Book title plain
-%--------------------
-%PAGES IN BOOKS:
-    %: (def) Pages in book plain
-% bkpg-par,%: Pages in book in parentheses
-% bkpg-x,%: Pages in book bare
-%--------------------
-%TOTAL PAGES OF A BOOK:
-    %: (def) Total book pages not printed
-% pg-bk,%: For book: 345 pages
-% pg-bk,pg-pre,%: Total book pages before publisher
-%--------------------
-%PUBLISHER ADDRESS:
-    %: (def) Publisher, address
-% add-pub,%: Address: Publisher
-%--------------------
-%PUBLISHER IN PARENTHESES:
-    %: (def) Publisher as normal block
-% pub-par,%: Publisher in parentheses
-% pub-date,%: Publisher and date in parentheses
-% pub-date,pub-xc,%: Publisher and date in parentheses, no comma
-% pub-date,pub-xpar,%: Publisher and date without parentheses
-% pub-date,pub-xpar,pub-xc,%: Publisher and date, no parentheses, no comma
-%--------------------
-%PUBLISHER POSITION:
-    %: (def) Publisher after chapter, pages
-% pre-pub,%: Publisher before chapter, pages
-% pre-edn,%: Publisher after edition
-%--------------------
-%ISBN NUMBER:
-% isbn,%: Include ISBN
-    %: (def) No ISBN
-%--------------------
-%ISSN NUMBER:
-% issn,%: Include ISSN
-    %: (def) No ISSN
-%--------------------
-%DOI NUMBER:
-% doi,%: Include DOI
-% agu-doi,doi,%: Insert DOI AGU style
-    %: (def) No DOI
-%--------------------
-%`EDITOR' AFTER NAMES (EDITED BOOKS WITHOUT AUTHORS):
-%   %: (def) Word `editor' after name
-  edpar,%: `Name (editor),'
-% edpar,bkedcap,%: `Name (Editor),'
-% edparc,%: `Name, (editor)'
-% edparc,bkedcap,%: `Name, (Editor)'
-% edparxc,%: `Name (editor)'
-% edparxc,bkedcap,%: `Name (Editor)'
-%--------------------
-%EDITOR IN COLLECTIONS:
-    %: (def) Same as for edited book
-% edby,%: In booktitle, edited by .. 
-% edby-par,%: In booktitle (edited by ..)
-% edby-parc,%: In booktitle, (edited by ..)
-% edby,edbyx,%: In booktitle, editor ..
-% edby,edbyw,%: In booktitle, (editor) ..
-% edby-par,edbyx,%: In booktitle (editor..)
-% edby-parc,edbyx,%: In booktitle, (editor..)
-% edby,edbyy,%: In booktitle, .., editor
-% edby-par,edbyy,%: In booktitle (.., editor)
-%--------------------
-%CAPITALIZE `EDITOR' OR `EDITED BY' (if editor capitalizable)
-%   %: (def) `(editor,..)' or `(edited by..)'
-% edcap,%: `(Editor,..)' or `(Edited by..)'
-%--------------------
-%PUNCTUATION BETWEEN SECTIONS (BLOCKS):
-    %: (def) \newblock after blocks
-% blk-com,%: Comma between blocks
-% blk-com,com-semi,%: Semi-colon between blocks
-% blk-com,com-blank,%: Blanks between blocks
-% blk-tit,%: Period after titles of articles, books, etc
-% blk-tita,%: Period after titles of articles
-%--------------------
-%PUNCTUATION BEFORE NOTES (if not using \newblock)
-%   %: (def) Notes have regular punctuation
-% blknt,%: Notes preceded by period
-%--------------------
-%PUNCTUATION AFTER AUTHORS:
-    %: (def) Author block normal
-% au-col,%: Author block with colon
-%--------------------
-%PUNCTUATION AFTER `IN':
-    %: (def) Space after `in'
-% in-col,%: Colon after `in'
-% in-it,%: Italic `in'
-% in-col,in-it,%: Italic `in' and colon
-% in-x,%: No word `in'
-%--------------------
-%`IN' WITH JOURNAL NAMES (if using 'in' with collections)
-    %: (def) No `in' before journal name
-% injnl,%: Add `in' before journal name
-%--------------------
-%FINAL PUNCTUATION:
-    %: (def) Period at very end
-% fin-bare,%: No period at end
-%--------------------
-%ABBREVIATE WORD `PAGES' (if not using external language file)
-    %: (def) `Page(s)'
-% pp,%: `Page' abbreviated
-% ppx,%: `Page' omitted
-%--------------------
-%ABBREVIATE WORD `EDITORS':
-    %: (def) `Editor(s)'
-% ed,%: `Editor' abbreviated
-%--------------------
-%OTHER ABBREVIATIONS:
-    %: (def) No abbreviations
-% abr,%: Abbreviations
-%--------------------
-%ABBREVIATION FOR `EDITION' (if abbreviating words)
-%   %: (def) `Edition' abbreviated as `edn'
-% ednx,%: `Edition' abbreviated as `ed'
-%--------------------
-%MONTHS WITH DOTS:
-%   %: (def) Months with dots
-% mth-bare,%: Months without dots
-%--------------------
-%EDITION NUMBERS:
-  xedn,%: Editions as in database
-%   %: (def) Write out editions
-% ord,%: Numerical editions
-%--------------------
-%Reading external language file \cfile=
-%STORED JOURNAL NAMES:
-    %: (def) Full journal names
-% jabr,%: Abbreviated journal names
-% jabr,jaa,%: Abbreviated with astronomy shorthands
-%--------------------
-%AMPERSAND:
-    %: (def) Use word `and'
-% amper,%: Use ampersand
-% varand,%: Use \BIBand
-%--------------------
-%COMMA BEFORE `AND':
-    %: (def) Comma before `and'
-% and-xcom,%: No comma before `and'
-% and-com,%: Comma even with 2 authors
-%--------------------
-%COMMA BEFORE `AND' EVEN FOR COLLECTION EDITORS (if using comma before `and' with authors)
-% and-com-ed,%: Comma with 2 editors
-%   %: (def) Two editors without comma
-%--------------------
-%NO `AND' IN REFERENCE LIST:
-    %: (def) With `and'
-% xand,%: No `and'
-%--------------------
-%FONT OF `ET AL':
-%   %: (def) Plain et al
-  etal-it,%: Italic et al
-% etal-rm,%: Roman et al
-%--------------------
-%ADDITIONAL REVTeX DATA FIELDS:
-    %: (def) No additional fields
-% revdata,eprint,url,url-blk,%: Include REVTeX data fields
-%--------------------
-%E-PRINT DATA FIELD: (without REVTeX fields)
-    %: (def) Do not include eprint field
-% eprint,%: Include eprint and archive fields
-%--------------------
-%URL ADDRESS: (without REVTeX fields)
-%   %: (def) No URL
-  url,url-blk,%: Include URL
-% url,url-nt,%: URL as note
-% url,url-nl,%: URL on new line
-%--------------------
-%REFERENCE COMPONENT TAGS:
-    %: (def) No reference component tags
-% bibinfo,%: Reference component tags
-%--------------------
-%EMPHASIS: (affects all so-called italics)
-    %: (def) Use emphasis
-% em-it,%: Use true italics
-% em-x,%: No italics
-% em-ul,%: Underlining
-%--------------------
-%COMPATIBILITY WITH PLAIN TEX:
-  nfss,%: Use LaTeX commands
-% plntx,%: Use only Plain TeX
-%--------------------
-  }}
-\generate{\file{tmr.bst}{\MBopts}}
-\endbatchfile
diff --git a/tests/BinaryTree.hs b/tests/BinaryTree.hs
deleted file mode 100644
--- a/tests/BinaryTree.hs
+++ /dev/null
@@ -1,57 +0,0 @@
-{-# OPTIONS_GHC -O2 -fasm #-}
-
-module BinaryTree where
-
-import Data.Ratio(Ratio, (%), numerator, denominator)
-
-
-data  Tree a b
-   =  Leaf    a
-   |  Branch  b (Tree a b) (Tree a b)
-      deriving (Eq,Show)
-
-childrenOf :: Tree a b ->  [Tree a b]
-childrenOf (Leaf    _      )  =   []
-childrenOf (Branch  _ l r  )  =   [l,r]
-
-fold :: (a -> c) -> (b -> c -> c -> c) -> Tree a b -> c
-fold leaf branch = loop
-    where
-       loop (Leaf    a      ) = leaf a
-       loop (Branch  b l r  ) = branch b (loop l) (loop r)
-
-labelDisj :: (a -> c) -> (b -> c) -> Tree a b -> c
-labelDisj leaf branch (Leaf    a      ) = leaf    a
-labelDisj leaf branch (Branch  b _ _  ) = branch  b
-
-
-
-fib n = fibs !! (n - 1)
-  where
-    fibs = Leaf 0 : Leaf 0 : zipWith3 Branch [1..] fibs (tail fibs)
-
-sternBrocot :: Tree a (Ratio Integer)
-sternBrocot = loop 0 1 1 0
-   where
-     loop a b x y
-         = Branch (m%n) (loop a b m n) (loop m n x y)
-           where
-             m  = a + x
-             n  = b + y
-
-toTikzString maxdepth branch leaf t = "  \\" ++ loop 0 t ";\n"
-  where
-    loop n t str
-      | n < maxdepth
-      = case t of
-         (Leaf a) -> "node {" ++ leaf a ++ "}" ++ str
-         (Branch b l r) -> "node {" ++ branch b ++ "}\n"
-                        ++ replicate (7*n+3) ' ' ++ "child {"
-                        ++ loop (n+1) l ("}\n" ++ replicate (7*n+3) ' '
-                                         ++ "child {" ++ (loop (n+1) r ("}" ++ str)))
-      | otherwise
-      = case t of
-          (Leaf a) -> "node {" ++ leaf a ++ "}" ++ str
-          (Branch b _l _r) -> "node {" ++ branch b ++ "} child {} child {}" ++ str
-
-toFrac x = "$\\frac{" ++ show (numerator x) ++ "}{" ++ show (denominator x) ++ "}$"
diff --git a/tests/BreadthFirstSearch.hs b/tests/BreadthFirstSearch.hs
deleted file mode 100644
--- a/tests/BreadthFirstSearch.hs
+++ /dev/null
@@ -1,203 +0,0 @@
-{-# OPTIONS_GHC -O2 -fasm              #-}
-{-# LANGUAGE BangPatterns              #-}
-{-# LANGUAGE NoMonomorphismRestriction #-}
-module BreadthFirstSearch where
-
-import BinaryTree
-import qualified Control.Monad.Queue.Allison  as A
-import qualified Control.Monad.Queue.Corec    as C
-import qualified Control.Monad.Queue.ST       as STQ
-import qualified CpSt
-import qualified SideChannelQ                 as SCQ
-import qualified Data.Queue.TwoStack          as Two
-import qualified Data.Queue.Okasaki           as Oka
-import Data.Sequence
-import qualified Data.Sequence as Seq
-
-isBranch = labelDisj (const False) (const True)
-
-direct ::  Tree a b  ->  [Tree a b]
-direct     tree      =   queue
-  where
-    queue  | isBranch tree   = tree :  explore 1 queue
-           | otherwise       =         explore 0 queue
-
-    explore :: Int -> [Tree a b] -> [Tree a b]
-    explore  0 _ = []
-    explore  (n+1) (Branch _ l r : head')
-      =  if (isBranch  l)
-         then   if (isBranch r)
-                then   l :  r :  explore  (  n+2)  head'
-                else   l :       explore  (  n+1)  head'
-         else   if (isBranch r)
-                then        r :  explore  (  n+1)  head'
-                else             explore     n     head'
-
-allison tree = A.runQueue (handle tree >> explore)
-  where
-    handle t@(Leaf   _      ) = return ()
-    handle t@(Branch _ _ _  ) = A.enQ t
-
-    explore = do
-      branch <- A.deQ
-      case branch of
-        Nothing -> return ()
-        (Just (Branch _ !l !r)) -> handle l >> handle r >> explore
-
-
-allison2  tree = A.runQueue (handle tree >> explore)
-  where
-    handle t@(Leaf   _      ) = return ()
-    handle t@(Branch _ _ _  ) = A.enQ t
-
-    explore = do
-      (Branch _ !l !r) <- A.deQ_break
-      handle l
-      handle r
-      explore
-
-
-stq tree = STQ.runResult (handle tree >> explore)
-  where
-    handle t@(Leaf   _      ) = return ()
-    handle t@(Branch _ _ _  ) = STQ.enQ t
-
-    explore = do
-      branch <- STQ.deQ
-      case branch of
-        Nothing -> return ()
-        (Just (Branch _ !l !r)) -> handle l >> handle r >> explore
-
-corec1   tree = case C.runResultQueue (handle tree >> explore) of
-                 (_,q) -> q
-  where
-
-    handle t@(Leaf   _      ) = return ()
-    handle t@(Branch _ _ _  ) = C.enQ t
-
-    explore = do
-      branch <- C.deQ
-      case branch of
-        Nothing -> return ()
-        (Just (Branch _ !l !r)) -> handle l >> handle r >> explore
-
-
-
-corec2   tree = case C.runResultQueue (handle tree >> explore) of
-                  ((),q) -> q
-  where
-    handle t@(Leaf   _      ) = return ()
-    handle t@(Branch _ _ _  ) = C.enQ t
-
-    explore = do
-      branch <- C.deQ
-      case branch of
-        Nothing -> return ()
-        (Just (Branch _ !l !r)) -> handle l >> handle r >> explore
-
-sidechan1 tree
-    = case SCQ.runResultQueue (handle tree >> explore) of
-        (_,q) -> q
-  where
-    handle t@(Leaf   _      ) = return ()
-    handle t@(Branch _ _ _  ) = SCQ.enQ t
-
-    explore = do
-      branch <- SCQ.deQ
-      case branch of
-        Nothing -> return ()
-        (Just (Branch _ !l !r)) -> handle l >> handle r >> explore
-
-
-
-sidechan2 tree
-    = case SCQ.runResultQueue (handle tree >> explore) of
-       ((),q) -> q
-  where
-    handle t@(Leaf   _      ) = return ()
-    handle t@(Branch _ _ _  ) = SCQ.enQ t
-
-    explore = do
-      branch <- SCQ.deQ
-      case branch of
-        Nothing -> return ()
-        (Just (Branch _ !l !r)) -> handle l >> handle r >> explore
-
-
-
-twostack t = loop (handle t Two.empty)
-  where
-    handle t@(Leaf   _    ) q = q
-    handle t@(Branch _ _ _) q = Two.enque t q
-
-    loop q = case Two.deque q of
-               (Nothing, q') ->  ()
-               (Just (Branch _ !l !r), q') -> loop (handle r (handle l q'))
-
-
-twostack_cpst tree = CpSt.runResult (handle tree >> explore)
-  where
-    handle t@(Leaf   _      ) = return ()
-    handle t@(Branch _ _ _  ) = CpSt.enQ t
-
-    explore = do
-      branch <- CpSt.deQ
-      case branch of
-        Nothing -> return ()
-        (Just (Branch _ !l !r)) -> handle l >> handle r >> explore
-
-
-twostack_list t = loop (handle t Two.empty)
-  where
-    handle t@(Leaf   _    ) q = q
-    handle t@(Branch _ _ _) q = Two.enque t q
-
-    loop q = case Two.deque q of
-               (Nothing, q') ->  []
-               (Just t@(Branch _ !l !r), q') -> t : loop (handle r (handle l q'))
-
-okasaki t = loop (handle t Oka.empty)
-  where
-    handle t@(Leaf   _    ) q = q
-    handle t@(Branch _ _ _) q = Oka.enque t q
-
-    loop q = case Oka.deque q of
-               (Nothing, q') ->  ()
-               (Just (Branch _ !l !r), q') -> loop (handle r (handle l q'))
-
-
-okasaki_list t = loop (handle t Oka.empty)
-  where
-    handle t@(Leaf   _    ) q = q
-    handle t@(Branch _ _ _) q = Oka.enque t q
-
-    loop q = case Oka.deque q of
-               (Nothing, q') ->  []
-               (Just t@(Branch _ !l !r), q') -> t:loop (handle r (handle l q'))
-
-sequence t = loop (handle t empty)
-  where
-    handle t@(Leaf   _    ) q = q
-    handle t@(Branch _ _ _) q = q |> t
-
-    loop q = case viewl q of
-               EmptyL -> ()
-               (Branch _ !l !r) :< q' -> loop (handle r (handle l q'))
-
-sequence_list t = loop (handle t empty)
-  where
-    handle t@(Leaf   _    ) q = q
-    handle t@(Branch _ _ _) q = q |> t
-
-    loop q = case viewl q of
-               EmptyL -> []
-               t@(Branch _ !l !r) :< q' -> t:loop (handle r (handle l q'))
-
-sequence2 t = loop (Seq.singleton t)
-   where
-   handle t@(Leaf   _     ) q = q
-   handle t@(Branch _ _ _ ) q = q |> t
-
-   loop q | Seq.null q = ()
-          | otherwise  = case Seq.index q 0 of
-                           x@(Branch _ l r) -> loop (handle r (handle l (Seq.drop 1 q)))
diff --git a/tests/CpSt.hs b/tests/CpSt.hs
deleted file mode 100644
--- a/tests/CpSt.hs
+++ /dev/null
@@ -1,23 +0,0 @@
-module CpSt (CpSt(..), get, put, enQ, deQ, runResult, runCpSt)  where
-
-import Data.Queue.TwoStack
-
-newtype CpSt r s a
-      = CpSt { unCpSt :: (a -> s -> r) -> s -> r }
-
-instance Monad (CpSt r s) where
-   return a  = CpSt (\k -> k a)
-   m >>= f   = CpSt (\k -> unCpSt m (\a -> unCpSt (f a) k))
-
-get     = CpSt (\k s -> k s   s   )
-put s'  = CpSt (\k _ -> k ()  s'  )
-
---runCpSt :: CpSt a s a -> s -> (a,s)
-runCpSt m s0 = unCpSt m (\a s -> (a,s)) s0
-
-enQ e = CpSt (\k q -> k () (enque e q))
-
-deQ   = CpSt (\k q -> case deque q of
-                        (e,q') -> k e q')
-
-runResult m = unCpSt m (\a s -> a) empty
diff --git a/tests/SideChannelQ.hs b/tests/SideChannelQ.hs
deleted file mode 100644
--- a/tests/SideChannelQ.hs
+++ /dev/null
@@ -1,72 +0,0 @@
-{-# OPTIONS_GHC -O2 -fno-full-laziness  #-}
-{-# LANGUAGE BangPatterns               #-}
-{-# LANGUAGE NoMonomorphismRestriction  #-}
--- Argh... for whatever reason this file cannot be compiled with optimization
--- -fno-full-laziness fixes this
--- Todo: check ghc-core to find out why
-
-module SideChannelQ (Q(), enQ, deQ, runResultQueue) where
-
---import Control.Monad.Queue.Class
-import Control.Monad.Cont.Class
-import Data.IORef
-import System.IO.Unsafe
-import qualified Debug.Trace
-
--- trace   = Debug.Trace.trace
--- traceIO = putStr
-
-trace   _ = id
-traceIO _ = return ()
-
-type QSt r' r  = IORef r' -> IORef [r] -> Int -> [r] -> [r]
-
-newtype Q r' r a = Q { unQ :: ((a -> QSt r' r) -> QSt r' r) }
-
-instance Monad (Q r' r) where
-    return a = Q ($a)
-    m >>= f  = Q (\k -> unQ m (\a -> unQ (f a) k))
-
-instance MonadCont (Q r' r) where
-  callCC f = Q (\k -> unQ (f (\a -> Q (\_ -> k a))) k)
-
-
-unsafeRead  ref   = unsafePerformIO (readIORef  ref  )
-unsafeWrite ref a = unsafePerformIO (writeIORef ref a)
-unsafeNew   a     = unsafePerformIO (newIORef   a    )
-
-
-enQ x = Q (\k rr' rr !n xs -> let !n' = n+1
-                                  xs'  = k () rr' rr n' xs
-                               in trace ("enQ $ " ++ show x)
-                                   (unsafeWrite rr xs' `seq` (x:xs')))
-
-deQ = Q delta
-  where
-    delta k rr' rr 0        xs  = trace ("deQ failed")     (k Nothing  rr' rr 0 xs)
-    delta k rr' rr (n+1) (x:xs) = trace ("deQ " ++ show x) (k (Just x) rr' rr n xs)
-
-
-breakK a rr' rr n xs = trace ("setting return value: " ++ show a)
-                         (unsafeWrite rr' (\() -> a) `seq` [])
-
-
-force [] = return ()
-force (_:_) = return ()
-
-demand [] = ()
-demand (_:_) = ()
-
-runResultQueue m
-     = (trace "reading return value" `seq` unsafeRead rr' (), queue)
-   where
-     rr' = unsafeNew init
-     init () = unsafePerformIO $ do
-                 traceIO "forcing computation\n"
-                 xs <- readIORef rr
-                 force xs
-                 traceIO "reading return value\n"
-                 f <- readIORef rr'
-                 return (f ())
-     rr  = unsafeNew queue
-     queue = unQ m breakK rr' rr 0 queue
diff --git a/tests/Time.hs b/tests/Time.hs
deleted file mode 100644
--- a/tests/Time.hs
+++ /dev/null
@@ -1,108 +0,0 @@
-
-{-# LANGUAGE BangPatterns #-}
-
-module Main where
-
-import qualified BinaryTree as T
-import qualified BreadthFirstSearch as BFS
-import qualified Data.Char as Char
-import Data.List
-import Data.Bits
-import System.CPUTime
-import System.Environment
-
-stats = foldl' (\(!s0,!s1,!s2) x -> (s0+1,s1+x,s2+x*x)) (0,0,0)
-
-stddev (s0,s1,s2) = sqrt (s0 * s2 - s1 * s1) / s0
-
-avg (s0,s1,s2) = s1 / s0
-
-fib :: Int -> Int
-fib n = snd . foldl' fib' (1, 0) $ dropWhile not $
-            [testBit n k | k <- let s = bitSize n in [s-1,s-2..0]]
-    where
-        fib' (f, g) p
-            | p         = (f*(f+2*g), ss)
-            | otherwise = (ss, g*(2*f-g))
-            where ss = f*f+g*g
-
-test string val = do
-  start <- getCPUTime
-  if val then return () else error ("Failed test: " ++ string)
-  end <- getCPUTime
-  return $! (end - start) `div` cpuTimePrecision
-
-test' string f i n = do
-  ts <- mapM (test string . f) (replicate n i)
-  putStr string
-  putStr "\nTimings: "
-  print ts
-  putStr "Sum:     "
-  print (sum ts)
-  putStr "Minimum: "
-  print (minimum ts)
-  putStr "Maximum: "
-  print (maximum ts)
-  let s = stats (map fromIntegral ts)
-  putStr "Mean:    "
-  print (avg s)
-  putStr "Stddev:  "
-  print (stddev s)
-
-
-fromQueue f n = length (f (T.fib n)) == fib n - 1
-
-fromUnit  f n = (f (T.fib n)) == ()
-
-main = do
-  xs <- getArgs
-  case xs of
-    (a1:a2:a3:_)
-        | all Char.isDigit a2 && all Char.isDigit a3
-        -> do_test a1 (read a2) (read a3)
-    _ -> help_message
-
-do_test a1 i n
- = case a1 of
-   "direct"         -> test' a1 (fromQueue BFS.direct        ) i n
-   "allison"        -> test' a1 (fromQueue BFS.allison       ) i n
-   "allison2"       -> test' a1 (fromQueue BFS.allison2      ) i n
-   "corec1"         -> test' a1 (fromQueue BFS.corec1        ) i n
-   "corec2"         -> test' a1 (fromQueue BFS.corec2        ) i n
-   "st"             -> test' a1 (fromUnit  BFS.stq           ) i n
-   "sidechan1"      -> test' a1 (fromQueue BFS.sidechan1     ) i n
-   "sidechan2"      -> test' a1 (fromQueue BFS.sidechan2     ) i n
-   "twostack"       -> test' a1 (fromUnit  BFS.twostack      ) i n
-   "two_cpst"       -> test' a1 (fromUnit  BFS.twostack_cpst ) i n
-   "two_list"       -> test' a1 (fromQueue BFS.twostack_list ) i n
-   "okasaki"        -> test' a1 (fromUnit  BFS.okasaki       ) i n
-   "okasaki_list"   -> test' a1 (fromQueue BFS.okasaki_list  ) i n
-   "sequence"       -> test' a1 (fromUnit  BFS.sequence      ) i n
-   "sequence_list"  -> test' a1 (fromQueue BFS.sequence_list ) i n
-   "sequence2"      -> test' a1 (fromUnit  BFS.sequence2     ) i n
-   _ -> help_message
-
-help_message = do
-  putStr   "Usage:  Time <test> <input> <number_of_trials>"
-  putStr "\n<test> is one of:"
-  putStr "\n   direct     for a corecursive traversal without using a monad"
-  putStr "\n   allison    Control.Monad.Queue.Allison"
-  putStr "\n   allison2     as above, but uses deQ_break instead of deQ"
-  putStr "\n   corec1       Control.Monad.Queue.Corec, does not demand result of ()"
-  putStr "\n   corec2       as above, but demands ()"
-  putStr "\n   sidechan1    SideChannelQ, like corec1"
-  putStr "\n   sidechan2    like corec2"
-  putStr "\n   twostack     Two-Stack queues without a monad"
-  putStr "\n   two_cpst     uses Two-Stack queues inside a CpSt monad"
-  putStr "\n   two_list     produces a list of elements enqueued"
-  putStr "\n   okasaki      Data.Queue.Okasaki"
-  putStr "\n   okasaki_list"
-  putStr "\n   sequence     Data.Sequence"
-  putStr "\n   sequence_list"
-  putStr "\n   sequence2    The wrong way to use sequence as a queue"
-  putStr "\n"
-  putStr "\ne.g.  Test direct 30 10"
-  putStr "\n        runs direct on the 30th fibbonacci tree 10 times"
-  putStr "\n      Test direct 30 10 +RTS -H500M -sstderr"
-  putStr "\n        as above, but uses a 500MB heap,  and prints runtime stats"
-  putStr "\n"
