I have the following Haskell type definition:
import Data.Sequence(Seq, length)
import Data.ByteString.UTF8(ByteString)
type StringSeq = Seq ByteString
I have expressions of type StringSeq
for which I would like to force strict evaluation with deepseq
. So I need to define instances of NFData
. I did the following:
import Control.DeepSeq(NFData, deepseq)
instance NFData ByteString
instance NFData a => NFData (Seq a) where
rnf s = rnf (length s)
So I compute the length of a sequence to force evaluation of the sequence itself. This seems to work but is this the correct implementation? Are there better ones? Does computing the length of a sequence introduce too much overhead?