News for hackers. Stuff that matters.
Re:Haskell Fan Site by afranchuk on Sunday June 23, 2019 @01:30PM (#20257175)
Yeah, I think it would need to be a language feature. Otherwise the memoization function itself, with state and conditional execution based on the state, isn't very straightforward.
Re:Haskell Fan Site by joppy on Sunday June 23, 2019 @07:17PM (#20259371)
In simple cases (for example a function UInt8 -> Something) it might be reasonable to expect the optimiser to know how to memoise automatically. But how about functions of the form (Integer -> Something), which have an essentially infinite domain? How much space is the memoization allowed to use? What kind of data structure should be used for the lookup? This could be very hard for the application programmer to communicate to the compiler.

Memoising a function f in Haskell can be done like this: create some lazy map where the keys are arguments, and the associated value is f(argument). The function f will only be evaluated once you actually try to use the values of the map.

Re:Haskell Fan Site by felixschl on Sunday June 23, 2019 @08:50PM (#20259697)
I thought the first example in this blog post on TH was an interesting idea: https://www.parsonsmatt.org/2015/11/15/template_haskell.html
Re:Haskell Fan Site by rocqua on Sunday June 23, 2019 @04:53PM (#20258575)
Best case scenario would be the optimizer does it for you. Less optimal would be compiler hints saying 'please memoize this function'.