How do I force evaluation?
Matthias Fischmann
fis@ssh.com
13 Mar 2001 09:40:09 +0200
Yes, that does not look very nice but it should work. In a private
response, I was also pointed out the alternative solution of using
case together with `seq` to trigger evaluation, which looked like the
default way to me (what else is seq for?):
| case monstrousDS `seq` True of True -> hPutStr stderr "ok."
I first tried to wrap this in a `force' function, thereby proving that
I still haven't grasped the concept entirely. (-:
But maybe it is possible to make a primitive of this in the same way
as has been done with assert?
Anyway thanks for all your help,
Matthias
"Jan de Wit" <jwit@studenten.net> writes:
> Hi,
>
> > I want to do something like:
> >
> > | main = do
> > | monstrousDataStructure <- monstrousComputation
> > | hPutStr stderr "success!"
> > | ...
> >
> > The important point is that I want to make sure that the computation
> > has terminated and not failed before I go to `...'.
> If the monstrous data structure has a 'serious' equality (not always
> returning True), you can try:
>
> | main = do
> | monstrousDataStructure <- monstrousComputation
> | if (monstrousDataStructure == monstrousDataStructure) then
> | hPutStr stderr "success!"
> | else
> | hPutStr stderr "failure?"
>
> The idea is that comparing for equality walks over the entire data
> structure, forcing evaluation because every location has to be inspected.
>
> Hope this helps,
> Jan de Wit
>
>
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users@haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>
--
Matthias Fischmann | Research Engineer | +358 (9) 8565 7474
fis@ssh.fi | SSH Communication Security Corp | +358 (40) 752 5291