-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Functions and collections #113
Conversation
|
||
<!--- INCLUDE | ||
|
||
fun fibonacciWorker(n: Int): Int = when (n) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is memoise
not valid for DeepRecursiveFunction
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how they work with each other, since DeepRecursiveFunction
has this weird callRecursive
.
If you define the memoized version of your function as a `val`, as we've done | ||
above, the cache is shared among **all** calls to your function. In the worst | ||
case, this may result in memory which cannot be reclaimed throughout the whole | ||
execution, so you should apply this technique carefully. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also add something about eviction policies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like:
There's some literature about eviction policies for memoization, but at the moment of writing
memoize
doesn't offer any type of control over the cached values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me, and perhaps also point them to Aedile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 5f8c5b2
I'm personally not fond of these APIs in Kotlin. They feel unnatural to me in Kotlin, similar to HKTs but less problematic since they're much less complex, but still simulated into the language. Where Haskell can do this naturally, and Scala has multiple parameter lists, Historically they come from funKtionale, whose author has since then left the Kotlin community. Many of the old funKtionale users are now relying on us for continued support of this functionality. It would probably be better served by a compiler plugin, (except As you already mentioned in the shared link. Caching is one of the hardest issues in software programming, and IMO The Fibonacci problem can also be solved by using lazy sequence: fun fibonacci(): Sequence<Int> =
generateSequence(Pair(0, 1)) { Pair(it.second, it.first + it.second) }
.map { it.first } For this reason I never made work of promoting them on the website. @raulraja originally convinced me of this, not sure how he currently feels about this. We tried removing them in 1.0.0 actually, but were met by resistance from funKtionale users and decided to keep them. Even convincing them to limit it to arity-9 proofed difficult. |
@nomisRev I've done two things to make clear that we're not very fond of
|
It's not a draft anymore, it's turned into |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of minor comments. Looks good to me, @serras
Co-authored-by: Francisco Diaz <francisco.d@47deg.com>
No description provided.