title: What is the fastest error monad in haskell?
body: <p>The Maybe/Either monad slows things down significantly. Does the use of some continuation monad for handling errors speeds things up? Is there such a thing as a "builtin continuation monad" or a "buitin error monad"? By builtin I mean something like ST.</p>
  
  <p><strong>Benchmark:</strong></p>
  
  <pre><code>import Criterion.Main                                          
  
  unsafeDiv x 0 = error "division by zero"                       
  unsafeDiv x y = x `div` y                                      
  
  safeDiv x 0 = Nothing                                          
  safeDiv x y = Just (x `div` y)                                 
  
  test1 :: Int -&gt; [Int]                                          
  test1 n = map (n `unsafeDiv`) [n,n-1..1]                       
  
  test2 :: Int -&gt; Maybe [Int]                                    
  test2 n = mapM (n `safeDiv`) [n-1,n-2..0]                      
  
  test3 :: Int -&gt; Maybe [Int]                                    
  test3 n = test3' Just [n-1,n-2..0]                             
    where test3' k []     = k []                                 
          test3' k (0:ns) = Nothing                              
          test3' k (n:ns) = test3' (k . (n:)) ns                 
  
  main = defaultMain                                             
    [ bench "test1" (nf test1 100000)                            
    , bench "test2" (nf test2 100000)                            
    , bench "test3" (nf test3 100000)                            
    ] 
  </code></pre>