git.iko.soy/typeable/attoparsec
on master help sign in
NFData instances for the Result types.
commitffa98cc4cf097aa6bfe753ebb58fa8bfed7062d7 authorBryan O'Sullivan <bos@serpentine.com> dateFri 13 Jan 2012, 15:57 (15 years ago) parent5ccadc1
2 files changed+17
Data/Attoparsec/ByteString/Lazy.hs+11 Data/Attoparsec/Text/Lazy.hs+6
Data/Attoparsec/ByteString/Lazy.hs+11
@@ -33,6 +33,7 @@ module Data.Attoparsec.ByteString.Lazy
3333 , eitherResult
3434 ) where
3535
36+import Control.DeepSeq (NFData(rnf))
3637import Data.ByteString.Lazy.Internal (ByteString(..), chunk)
3738import qualified Data.ByteString as B
3839import qualified Data.Attoparsec.ByteString as A
@@ -53,6 +54,16 @@ data Result r = Fail ByteString [String] String
5354 -- input that had not yet been consumed (if any) when
5455 -- the parse succeeded.
5556
57+instance NFData r => NFData (Result r) where
58+ rnf (Fail bs ctxs msg) = rnfBS bs `seq` rnf ctxs `seq` rnf msg
59+ rnf (Done bs r) = rnfBS bs `seq` rnf r
60+ {-# INLINE rnf #-}
61+
62+rnfBS :: ByteString -> ()
63+rnfBS (Chunk _ xs) = rnfBS xs
64+rnfBS Empty = ()
65+{-# INLINE rnfBS #-}
66+
5667instance Show r => Show (Result r) where
5768 show (Fail bs stk msg) =
5869 "Fail " ++ show bs ++ " " ++ show stk ++ " " ++ show msg
Data/Attoparsec/Text/Lazy.hs+6
@@ -33,6 +33,7 @@ module Data.Attoparsec.Text.Lazy
3333 , eitherResult
3434 ) where
3535
36+import Control.DeepSeq (NFData(rnf))
3637import Data.Text.Lazy.Internal (Text(..), chunk)
3738import qualified Data.Attoparsec.Internal.Types as T
3839import qualified Data.Attoparsec.Text as A
@@ -57,6 +58,11 @@ instance Show r => Show (Result r) where
5758 "Fail " ++ show bs ++ " " ++ show stk ++ " " ++ show msg
5859 show (Done bs r) = "Done " ++ show bs ++ " " ++ show r
5960
61+instance NFData r => NFData (Result r) where
62+ rnf (Fail bs ctxs msg) = rnf bs `seq` rnf ctxs `seq` rnf msg
63+ rnf (Done bs r) = rnf bs `seq` rnf r
64+ {-# INLINE rnf #-}
65+
6066fmapR :: (a -> b) -> Result a -> Result b
6167fmapR _ (Fail st stk msg) = Fail st stk msg
6268fmapR f (Done bs r) = Done bs (f r)