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.
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.
Simply type a let followed by a newline: let ⏎. Then fac 0 = 1 ⏎. Then fac n = n * fac (n-1) ⏎ ⏎ and you're done!
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With