<div dir="ltr">quickfix: 10M'th, not 1M'th of course.<div><br></div><div><br></div><div>Cheers,</div><div>Ilya</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 7, 2015 at 6:11 PM, Ilya Razenshteyn <span dir="ltr"><<a href="mailto:ilyaraz@gmail.com" target="_blank">ilyaraz@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi everyone,</div><div><br></div><div>I'm new to Haskell and decided to learn a bit about monads and their utility. Actually, what worked nicely for me was: to read first several pages from "Computational lambda-calculus and monads", then do exercises from <a href="https://tonymorris.github.io/blog/posts/20-intermediate-haskell-exercises/" target="_blank">https://tonymorris.github.io/blog/posts/20-intermediate-haskell-exercises/</a>, and then map these exercises to actual functions in the standard library.</div><div><br></div><div>Then, I decided to implement memoization to practice a bit with ST, HashTable's and such. Here is what I managed to get: <a href="http://pastebin.com/79pwjLPL" target="_blank">http://pastebin.com/79pwjLPL</a> . This code computes Fibonacci numbers while caching the intermediate values in a hash table. I tried to make the code as fast as possible (it runs in under 15 seconds, when computing 1M'th Fibonacci number modulo 999983). It uses the package hashtables.</div><div><br></div><div>I have several question about all this.</div><div><br></div><div>First, is there a cheap way to speed this code up? Note that I'm interested in a universal memoization strategy, that is I don't want to use arrays instead of hash tables etc.</div><div><br></div><div>Second, is this code the right way of doing what it does (assuming that I really care about the performance)?</div><div><br></div><div>Third question. Currently, the code passes "cache" everywhere. It would be natural to combine ST with something like ReaderT to store it there. What is a way to do it? I tried something like "ReaderT (HashTable s) (ST s) Int", but I have not managed to get it work.</div></div>
</blockquote></div><br></div>