[Haskell-beginners] How memorize intermediate computation value[my brain is so hurt]?

Benjamin Edwards edwards.benj at gmail.com
Sat Feb 4 11:47:15 CET 2012


This might help :)

http://www.kennknowles.com/blog/2008/05/10/debugging-with-open-recursion-mixins/

On 4 February 2012 10:36, anyzhen <jiangzhen3s at qq.com> wrote:
> there have a lot of situation we need memorize intermediate computation
> value.
> and use in further.
> like this, compute nth fib question.
> So,how memorize it?
>
> i have an ugly solution.it used HashTable for memorization.
>
> fib n table
>  | n==1 =1
>  | n==2 =1
>  | otherwise =
>   case lookup table of
>     Just v   ->(v,table)
>     Nothing ->let (v,table') = fib (n-1) table in
>                    let ( v',table'')= v + fib(n-2) table' in
>                    (v',table'')
>
> i am an beginner come from imperative programming language.
> so fib memorize version program hurt my brain ... particular in Nothing
> branches.
> so do you have some good idea
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



More information about the Beginners mailing list