
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"
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

On Tue, Mar 13, 2001 at 09:40:09 +0200, Matthias Fischmann wrote:
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?):
suppose sth. like: foo someRecord = do ... foo someRecord{ field = field' } this may lead to quite some memory allocation (I had this case once, IIRC), and eventually it can be reduced by using `seq`: foo someRecord = do ... let r = someRecord{ field = field' } r `seq` foo r
| case monstrousDS `seq` True of True -> hPutStr stderr "ok."
*hmm* this just evaluates to WHNF, no?
From hugs:
Prelude> case (42,error "foo") `seq` True of True -> putStrLn "yow" yow
I first tried to wrap this in a `force' function, thereby proving that I still haven't grasped the concept entirely. (-:
forceEval x = if x == x then x else x but this *still* needs a decent equality on `x'... 8->
But maybe it is possible to make a primitive of this in the same way as has been done with assert?
This would definitely help to e.g. keep exceptions inside `catch'-blocks sometimes (of course at the expense of not being able to use infinite data structures at the same time there)... Cheers, Michael -- /~\ ASCII ribbon | "I would rather spend 10 hours reading someone else's \ / campaign | source code than 10 minutes listening to Musak waiting X against | for technical support which isn't." / \ HTML mail | -- Dr. Greg Wettstein, Roger Maris Cancer Center
participants (2)
-
Matthias Fischmann
-
Michael Weber