
I'm curious: is there a reliable way to force Haskell to recompute a function application instead of sharing the result of the forced thunk? For example, suppose I have a function f and two arguments e1 and e2, and I want to compare the time it takes to compute f e1 vs. f e2, but ghci reports that each takes 0.00 sec (i.e., less than 0.005 sec) to compute. The traditional approach would be to compute each value a large number of times so that the total time becomes significant, except that all of the ways I can think of to do that in Haskell don't actually recompute the function application, but rather compute it once and share, or otherwise optimize away the redundant computation. Todd Wilson, PhD Department of Computer Science California State University, Fresno

You could return it into IO couldn't you?
Prelude> let f a = return (a + 1)
Prelude> :t f
f :: (Num a, Monad m) => a -> m a
Prelude> let g = f :: Num a => a -> IO a
Prelude> :t g
g :: Num a => a -> IO a
Prelude> let blah = g 1
Prelude> :t blah
blah :: Num a => IO a
Prelude> blah
2
Prelude> :sprint blah
blah = _
--- Chris Allen
On Wed, Nov 19, 2014 at 1:39 AM, Todd Wilson
I'm curious: is there a reliable way to force Haskell to recompute a function application instead of sharing the result of the forced thunk? For example, suppose I have a function f and two arguments e1 and e2, and I want to compare the time it takes to compute f e1 vs. f e2, but ghci reports that each takes 0.00 sec (i.e., less than 0.005 sec) to compute. The traditional approach would be to compute each value a large number of times so that the total time becomes significant, except that all of the ways I can think of to do that in Haskell don't actually recompute the function application, but rather compute it once and share, or otherwise optimize away the redundant computation.
Todd Wilson, PhD Department of Computer Science California State University, Fresno _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Tue, Nov 18, 2014 at 11:39:37PM -0800, Todd Wilson wrote:
For example, suppose I have a function f and two arguments e1 and e2, and I want to compare the time it takes to compute f e1 vs. f e2
If your purpose is benchmarking (and even if it isn't) I suggest you look at how criterion manages the issue http://www.serpentine.com/criterion/tutorial.html

Looks like http://hackage.haskell.org/package/base-4.7.0.1/docs/Control-Exception.html#... ? https://github.com/bos/criterion/blob/master/Criterion/Types.hs#L290-L295 On Wed, Nov 19, 2014 at 1:55 AM, Tom Ellis < tom-lists-haskell-cafe-2013@jaguarpaw.co.uk> wrote:
On Tue, Nov 18, 2014 at 11:39:37PM -0800, Todd Wilson wrote:
For example, suppose I have a function f and two arguments e1 and e2, and I want to compare the time it takes to compute f e1 vs. f e2
If your purpose is benchmarking (and even if it isn't) I suggest you look at how criterion manages the issue
http://www.serpentine.com/criterion/tutorial.html _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Thanks, Chris and Tom, your posts contained exactly what I was looking for.
--Todd
Todd Wilson, PhD
Department of Computer Science
California State University, Fresno
On Tue, Nov 18, 2014 at 11:58 PM, Christopher Allen
Looks like http://hackage.haskell.org/package/base-4.7.0.1/docs/Control-Exception.html#... ?
https://github.com/bos/criterion/blob/master/Criterion/Types.hs#L290-L295
On Wed, Nov 19, 2014 at 1:55 AM, Tom Ellis < tom-lists-haskell-cafe-2013@jaguarpaw.co.uk> wrote:
On Tue, Nov 18, 2014 at 11:39:37PM -0800, Todd Wilson wrote:
For example, suppose I have a function f and two arguments e1 and e2, and I want to compare the time it takes to compute f e1 vs. f e2
If your purpose is benchmarking (and even if it isn't) I suggest you look at how criterion manages the issue
http://www.serpentine.com/criterion/tutorial.html _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Control.Exception.evaluate doesn't have much to do with forcing recomputation. If the argument is already in whnf, evaluate won't do anything. On 19/11/14 09:58, Christopher Allen wrote:
Looks like http://hackage.haskell.org/package/base-4.7.0.1/docs/Control-Exception.html#... ?
https://github.com/bos/criterion/blob/master/Criterion/Types.hs#L290-L295
On Wed, Nov 19, 2014 at 1:55 AM, Tom Ellis
mailto:tom-lists-haskell-cafe-2013@jaguarpaw.co.uk> wrote: On Tue, Nov 18, 2014 at 11:39:37PM -0800, Todd Wilson wrote: > For example, suppose I have a function f and two arguments e1 > and e2, and I want to compare the time it takes to compute f e1 vs. f > e2
If your purpose is benchmarking (and even if it isn't) I suggest you look at how criterion manages the issue
participants (4)
-
Christopher Allen
-
Roman Cheplyaka
-
Todd Wilson
-
Tom Ellis