2

Being rather new to pure functional programming idiom, I can't get how to implement this case of dynamic programming. I have a function f :: String -> [String] which is calculated recursively and want to memoize it. Input Strings can be arbitrary, so I guess that something like a lazy Map is needed, but couldn't find any. How to implement such case in Haskell?

1
  • 3
    Have you looked on Hackage? There's about a dozen memoization libraries available... Commented Oct 14, 2012 at 9:32

1 Answer 1

1

Use a memoizer library:

import qualified Data.MemoCombinators as Memo

f :: String -> [String]
f = Memo.list Memo.char memof  -- because String = [Char]
    where
    memof x = ... f ...          -- call *f* recusively (not memof)

See the documentation for more. Also see MemoTrie

Sign up to request clarification or add additional context in comments.

1 Comment

I didn't think that it's implemented as an external library and didn't search search at hackage. And it seems strange that such functions are not in the default GHC libraries.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.