logo
首页技术栈工具库讨论
runmemo

runmemo

This library encourages you to do memoization in three separate steps: Create a memoizable function Create or select an appropriate memoizer Run the memoizer on the memoizable function Let's start with the first. When you create a memoizable function, you should use the self convention, which is that the first input to the function is self, and all recursive calls are replaced with self. One common convention that goes well with the self convention is using a helper function go, like so: Now for the second. For this example, we need a Memoizer that can handle an Integer input, and an Integer output. Data.MemoCombinators provides integral, which handles any Integral input, and any output. Data.MemoUgly provides memo, which can memoize any function a -> b, given an Ord instance for a. Third, let's run our memoizers! Since we have decoupled the definition of the memoized function from its actual memoization, we can create multiple memoized versions of the same function if we so desire. You could easily do the same with Data.MemoTrie.memo, Data.Function.Memoize.memoize, etc. Using this technique, you can create local memoized functions whose memo tables are garbage collected as soon as they are no longer needed.
由 
bruceshi2021-01-13 收录
--
推荐
不推荐
更多信息
GitHub iconDanBurton/runmemo9
HACKAGE
carbal install runmemo
查看
标签
根据用户添加的标签生成
暂无标签