arrow-kt / arrow-website

This is the main website for Arrow, the functional companion to Kotlin's Standard Library
https://arrow-kt.io
Apache License 2.0
10 stars 22 forks source link

Documentation for MemoizedDeepRecursiveFunction #215

Closed serras closed 1 year ago

serras commented 1 year ago

Fixes #213

serras commented 1 year ago

I appreciate the improvements you've made, and it seems like you've addressed the issue with the example. However, now there is a lack of demonstration or illustration of the actual .memoized() function, which is designed to work seamlessly with any non-recursive method.

I was actually debating what to do here. On the one hand, memoized works on every function; but if that function is recursive the recursive calls are not handled correctly. And if you're writing the recursive function by hand, you're better off using DeepRecursiveFunction than creating a double-recursive function in which the worker calls the memoized function and vice versa.

AcartN commented 1 year ago

I appreciate the improvements you've made, and it seems like you've addressed the issue with the example. However, now there is a lack of demonstration or illustration of the actual .memoized() function, which is designed to work seamlessly with any non-recursive method.

I was actually debating what to do here. On the one hand, memoized works on every function; but if that function is recursive the recursive calls are not handled correctly. And if you're writing the recursive function by hand, you're better off using DeepRecursiveFunction than creating a double-recursive function in which the worker calls the memoized function and vice versa.

In my opinion, there are really two cases:

I believe that in the documentation, both the simple .memoized() approach for a function and the usage of MemoizedDeepRecursiveFunction should be discussed, with a clear explanation of the differences between them. For someone who is new to the documentation, it is not obvious at all, so providing explanations and even illustrating with examples would be beneficial

-- EDIT: That being said, since the focus of this documentation page is on recursive functions, it might be more appropriate to discuss memoization of non-recursive functions in a separate section or dedicate a separate documentation page to it.

serras commented 1 year ago

@AcartN your explanation makes a lot of sense. I've just pushed a new commit with adds a new separate Memoization section. I've decided to still have "recursive + memoized" live in the Recursion section, because I feel it makes sense to tell the story in that way. In Memoization the discussion is about what are the limitations of memoize w.r.t. recursion, and then suggests MemoizedDeepRecursiveFunction as the preferred option if you control the function.

nomisRev commented 1 year ago

This documentation PR is blocked until we released 1.2.0.