How do I force evaluation?

Jan de Wit Jan de Wit" <jwit@studenten.net
Mon, 12 Mar 2001 10:38:23 +0100


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