[Haskell-beginners] deep seq and bang patterns

Emmanuel Touzery etouzery at gmail.com
Tue Dec 25 13:17:56 CET 2012


Hello,

 laziness just gave me some headache now. Because some of my code was
evaluated much later, well first the memory use exploded but also I got an
error which was really difficult to understand because it manifested much
later than I would intuitively expect (when I read the record field, not
when I wrote it...).

 Now, if nothing else for space usage needs, I need to make this strict.

 At first I tried bang patterns on my record:

{-# LANGUAGE BangPatterns #-}

data TvShow = TvShow
    {
        channel :: Channel,
        title :: !T.Text,
        startTime :: !T.Text,
        summary :: !T.Text
    }
    deriving (Eq, Show)

 That did not help.

 Then I tried deepseq:

instance NFData TvShow

    return $!! result

 That did not help.

 And here's the catch: doing BOTH helps... I mean I think I'll check it
again because I find it hard to believe but right now it really seems it
behaves like that...

 Is that possible? That I need to combine BOTH deepseq and bang patterns to
actually get my code to evaluate when filling in the data? Or am I going
crazy?

 Thank you!

Emmanuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121225/cc3006c4/attachment.htm>


More information about the Beginners mailing list