Re: [Haskell] Monad transformer question
Lajos, Point taken, thanks. My question, though, is not as much about how I speed up my program, as it is about the behaviour of the ReaderT monad transformer. There is something I do not understand about it, namely, why does such a small change in the code change the behaviour so much. Regards, Cyril
Based on what you wrote, I'm not sure that monads are the right answer in this situation. It seems like to me that simple memoization of function values would yield a purely functional but equally efficient solution.
A typical way to memoize the fibonacci function:
fib = ((map fib' [0 ..]) !!) where fib' 0 = 0 fib' 1 = 1 fib' n = fib (n - 1) + fib (n - 2)
(It only gives you a speed up if you compile with -O2 though.)
Regards,
Lajos Nagy
participants (1)
-
Cyril Schmidt