News for hackers. Stuff that matters.
Re:Dynamic programming in Haskell: automatic memoization by throwaway81523 on Tuesday June 20, 2023 @02:50AM (#36400566)
Maybe you mean using lazy evaluation as a memoization hack? That is a well known trick in Haskell though I agree it is in some ways cringy, relying on the evaluation strategy like that. But there are some Hackage packages that make it fairly convenient to use. I did a naive implementation myself and benchmarked it against an explicit STRef as a cache cell. I don't remember the result but it wasn't a huge (OOM+) difference iirc. Rather than using an array as the memo cache (which means you must know its size in advance), it's nicer to use an infinite branching tree.
Re:Dynamic programming in Haskell: automatic memoization by kccqzy on Tuesday June 20, 2023 @12:29PM (#36406539)
Right. Personally I'd be much happier using an STRef. The code is much more explicit.
Re:Dynamic programming in Haskell: automatic memoization by throwaway81523 on Tuesday June 20, 2023 @06:34PM (#36411652)
The trouble then is that you have to wrap the memoized function and everything that uses it in the ST monad. Lazy evaluation is completely pure.