Skip to content

Beginner's question in regard to borrowing ("^") #347

Answered by anfelor
JanBeh asked this question in Q&A
Discussion options

You must be logged in to vote

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 like length:

fun length( xs : list<a>)  : int
  match xs
     Cons(x, xx) -> 1 + length(xx)
     Nil -> Nil

Normally, when computing length(xs), Koka would transfer ownership of xs to the length function. However, let us assume that you intend to use xs further aft…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@JanBeh
Comment options

Answer selected by JanBeh
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants