diff --git a/derive.cabal b/derive.cabal
--- a/derive.cabal
+++ b/derive.cabal
@@ -1,7 +1,7 @@
 cabal-version:  1.18
 build-type:     Simple
 name:           derive
-version:        2.6.4
+version:        2.6.5
 copyright:      Neil Mitchell 2006-2017
 author:         Neil Mitchell <ndmitchell@gmail.com> and others
 maintainer:     None
diff --git a/src/Data/Derive/DSL/HSE.hs b/src/Data/Derive/DSL/HSE.hs
--- a/src/Data/Derive/DSL/HSE.hs
+++ b/src/Data/Derive/DSL/HSE.hs
@@ -99,7 +99,10 @@
           res = evalState (fromConstrM f $ readCon dat str) args
           f :: Data a => State [Output] a
           f = res where res = if typeOf (fromState res) == typeOf sl then return $ coerce sl else
-                              do x:xs <- get; put xs; return $ fromOutput x
+                              do l <- get
+                                 case l of
+                                     x:xs -> do put xs; return $ fromOutput x
+                                     [] -> error "fromOutput: null"
 
 fromOutput (OString x) = coerce x
 fromOutput (OInt x) = coerce x
diff --git a/src/Data/Derive/DSL/SYB.hs b/src/Data/Derive/DSL/SYB.hs
--- a/src/Data/Derive/DSL/SYB.hs
+++ b/src/Data/Derive/DSL/SYB.hs
@@ -27,13 +27,13 @@
 
 dlistAny :: forall a . Data a => DSL -> Maybe a
 dlistAny x | isNothing con = Nothing
-           | otherwise = res 
+           | otherwise = res
     where
         con = readConstr dat "(:)"
         val = fromConstr (fromJust con) :: a
-        
+
         dat = dataTypeOf (undefined :: a)
-        
+
         res = gmapQi 0 f val
 
         f :: Data d => d -> Maybe a
@@ -56,10 +56,14 @@
         f :: forall b . Data b => State (Bool,[DSL]) b
         f = if typeOf (undefined :: b) == typeOf sl then return $ coerce sl
             else do
-                (b,x:xs) <- get
-                case syb x of
-                    Nothing -> do put (False,xs) ; return undefined
-                    Just y -> do put (b,xs) ; return y
+                (b,l) <- get
+                case l of
+                    x:xs ->
+                        case syb x of
+                            Nothing -> do put (False,xs) ; return undefined
+                            Just y -> do put (b,xs) ; return y
+                    [] ->
+                        error "dapp: null"
 
 
 dsimple :: Data a => DSL -> Maybe a
