[Haskell-cafe] enforcing strictness on arbitrary subexpressions

Matthias Fischmann fis at wiwi.hu-berlin.de
Thu Feb 16 05:16:55 EST 2006



hei,

I want to force evaluation on an arbitrary expression.  What I have
found is only strict datatypes (the '!' thing), but not a strictness
idiom for arbitrary subexpressions.  (I want this for debugging
mostly, so if there is a better way to unsafePerformIO something in
one piece I would be happy with that, too.)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
veryLongString = "..."

data StrictThingy = StrictThingy ! String

main :: IO ()
main = do
       hPutStr stdout veryLongString  -- lazy
       veryLongString `seq` hPutStr stdout veryLongString  -- still lazy?
       (StrictThingy veryLongString) `seq` hPutStr stdout veryLongString  -- strict (or at least i hope it is)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Problem with the last line is that it doesn't work for arbitrary
types, and it's kind of ugly.  What I would like to have is something
like:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hPutStr stdout ! veryLongString
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

but I guess it's not that easy?

Sorry for asking without consulting the list archives, but I promise
I'll add it to the faq in the wiki once i understood.  (-:

I am using ghci and ghc, latest ubuntu package, but I am happy to
switch to new versions.

thanks,
matthias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org//pipermail/haskell-cafe/attachments/20060216/b23c41d4/attachment.bin


More information about the Haskell-Cafe mailing list