[Haskell-cafe] Forcing recomputation
Christopher Allen
cma at bitemyapp.com
Wed Nov 19 07:52:26 UTC 2014
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 <twilson at csufresno.edu> wrote:
> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20141119/6d8cb532/attachment.html>
More information about the Haskell-Cafe
mailing list