Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear ghci's function result cache?

Tags:

haskell

ghci

GHCI seems to cache the results of functions during an interactive session. It's easy to notice, just call a time-consuming function twice. On the second time, the result will appear immediately.

Is there a way to clear this cache from within GHCI so I don't have to restart it? I'm doing some quick'n'dirty non-detailed performance comparisons, so using System.CPUTime instead would be overkill.

like image 209
user42179 Avatar asked Mar 18 '13 18:03

user42179


People also ask

Does Haskell cache?

Memoization is an optimization technique used to speed up a function by caching its previously computed results. In impure programming languages, a mutable map is used to cache computed results.

How to define function in GHCi?

Simply type a let followed by a newline: let ⏎. Then fac 0 = 1 ⏎. Then fac n = n * fac (n-1) ⏎ ⏎ and you're done!

How to load file in GHCi?

GHCi is the interactive interface to GHC. From the command line, enter "ghci" (or "ghci -W") followed by an optional filename to load. Note: We recommend using "ghci -W", which tells GHC to output useful warning messages in more situations. These warnings help to avoid common programming errors.

What does return do in Haskell?

return is actually just a simple function in Haskell. It does not return something. It wraps a value into a monad. Looks like return is an overloaded function.


1 Answers

You can always reload the module you're working in via the command :r. This will throw away any interactive bindings you have made, and that might not always be practical if you're just poking around. This also works if you're not actually using a module.

like image 63
yatima2975 Avatar answered Oct 27 '22 00:10

yatima2975