Timing Functions

Georg Martius mai99dgf at studserv.uni-leipzig.de
Tue Jan 18 09:03:16 EST 2005


Hi Bill,

please note that "null list" just forces the first cell to be evaluated. I.e. the list (x: xs), just x is evaluated, but not xs. That means, that just the code in you function is evaluated that is really required for x.
If your return type is a list, then you might get away with determining the length, but again it will not force the inside of each cell. The only way to force full evaluation is the DeepSeq class, see [1]. In case you can show your type you can also do that, but it will warp you results obviously.

Regards,
	Georg

[1] http://www.mail-archive.com/haskell@haskell.org/msg15819.html

On Mon, 17 Jan 2005 14:21:00 -0600, jekwtw <jeaniek7 at comcast.net> wrote:

> Many thanks to both Georg and Lemmih.  Actually, I had considered laziness,
> but I didn't pursue it enough.  I tried one version of runNReps in which I
> passed (f x) as an additional arg; when that didn't work, a little thought
> convinced me that laziness was doing me in.  I also tried another approach,
> which was to "use" the function evaluation, but that didn't work either
> (note: I know (f x) can not be the empty list for values of x I'm interested
> in, but I don't think Haskell does, unless it's *really* smart :-) :
>
>> runNReps :: (Int -> [a]) -> Int -> Int -> IO ()
>> runNReps f x todo
>>             | todo > 0 = do let junk = (f x)
>>                                     if null junk then return (()) else
> runNReps f x (todo - 1)
>>             | otherwise = return (())
>
> Ideas?
>
> Again, many thanks,
>
>  -- Bill Wood
>     bill.wood at acm.org
>
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>



-- 

---- Georg Martius,  Tel: (+49 34297) 89434 ----
------- http://www.flexman.homeip.net ---------


More information about the Glasgow-haskell-users mailing list