diff --git a/Database/Persist/Base.hs b/Database/Persist/Base.hs
--- a/Database/Persist/Base.hs
+++ b/Database/Persist/Base.hs
@@ -68,7 +68,7 @@
 import qualified Control.Monad.IO.Class as Trans
 
 import qualified Control.Exception as E
-import Control.Monad.Error.Class (Error (..))
+import Control.Monad.Trans.Error (Error (..))
 
 import Data.Bits (bitSize)
 import Control.Monad (liftM)
@@ -77,7 +77,6 @@
 import qualified Data.Text.Encoding.Error as T
 import Web.PathPieces (SinglePiece (..))
 import qualified Data.Text.Read
-import Data.Maybe (fromMaybe, isJust)
 
 import Control.Monad.IO.Control (MonadControlIO)
 import Data.Object (TextObject)
@@ -500,15 +499,12 @@
             Just _ -> return False
 
 limitOffsetOrder :: PersistEntity val => [SelectOpt val] -> (Int, Int, [SelectOpt val])
-limitOffsetOrder opts = let (l,o,ord) = go opts (Nothing, Nothing, []) in
-    (fromMaybe 0 l, fromMaybe 0 o, ord)
+limitOffsetOrder opts =
+    foldr go (0, 0, []) opts
   where
-    go []              tup = tup
-    go (LimitTo  x:xs) (_,o,ord) = let tup = (Just x, o, ord) in
-      if isJust o then tup else go xs tup
-    go (OffsetBy x:xs) (l,_,ord) = let tup = (l, Just x, ord) in
-      if isJust l then tup else go xs tup
-    go (x:xs)          (l, o, ord) = go xs (l,o,x:ord)
+    go (LimitTo l) (_, b, c) = (l, b ,c)
+    go (OffsetBy o) (a, _, c) = (a, o, c)
+    go x (a, b, c) = (a, b, x : c)
 
 -- | Call 'select' but return the result as a list.
 selectList :: (PersistEntity val, PersistBackend b m)
diff --git a/Database/Persist/GenericSql.hs b/Database/Persist/GenericSql.hs
--- a/Database/Persist/GenericSql.hs
+++ b/Database/Persist/GenericSql.hs
@@ -153,9 +153,7 @@
     selectEnum filts opts =
         Iteratee . start
       where
-        limit  = fst3 $ limitOffsetOrder opts
-        offset = snd3 $ limitOffsetOrder opts
-        orders = third3 $ limitOffsetOrder opts
+        (limit, offset, orders) = limitOffsetOrder opts
 
         start x = do
             conn <- SqlPersist ask
diff --git a/persistent.cabal b/persistent.cabal
--- a/persistent.cabal
+++ b/persistent.cabal
@@ -1,5 +1,5 @@
 name:            persistent
-version:         0.6.3
+version:         0.6.4
 license:         BSD3
 license-file:    LICENSE
 author:          Michael Snoyman <michael@snoyman.com>
