-
Hi, I'm totally new to Koka and I hope it's okay to ask beginner's questions here? Checking the type of
The documentation on
This made me wonder what the
And:
Is |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @JanBeh, thanks for your question! Yes, the
Normally, when computing |
Beta Was this translation helpful? Give feedback.
-
Yes, it can be a CPU vs memory trade-off and that's how we analysed it initially. But over time we realized that it's also a consideration of whether the function is in practice called with the last reference to an object or not. If you always pass a shared object as borrowed, there is improved time but no increase in memory usage. But if you always pass a unique object, borrowing increases memory usage and is even worse on time: after your function finishes, a separate free-ing pass is required which could have been done in the function itself (consider how the length function can free the input list as it computes the length if the input list is unique and not borrowed). For this reason, borrowing is opt-in in Koka and not automatic like in Lean.
…On 1 August 2023 20:32:32 CEST, Jan Behrens ***@***.***> wrote:
Thanks for pointing me to these publications! I'll read into them.
I think it would be nice to see the documentation updated at some point in future to explain when it's wise to use these annotations. If I understand right, it's a CPU vs memory trade-off (borrowing can increase memory use).
--
Reply to this email directly or view it on GitHub:
#347 (reply in thread)
You are receiving this because you commented.
Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
Hi @JanBeh, thanks for your question! Yes, the
^
is a borrowing annotation. Unlike in Rust, these annotations only matter for performance and do not influence the types of the program -- so you do not have to worry about the compiler rejecting your program if you get something wrong there. In Koka, borrowing is a technique for improving the performance of a program by omitting reference counting operations. Consider a function likelength
:Normally, when computing
length(xs)
, Koka would transfer ownership ofxs
to thelength
function. However, let us assume that you intend to usexs
further aft…