-
Notifications
You must be signed in to change notification settings - Fork 26
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
borrowing in a high order function creeps internal details into the caller #859
Comments
It seems to me that when you took this step, you took a step to far, because the call to Do I need to introduce the borrowed block in order to borrow the linear reference, or can I just pass the linear reference to the function that borrows it? That is, can I just write
|
as I understand, either you do the block borrowing or you declare the type variable in the lambda as To make it clear: fun liftvL[linear t](item: t): Par[t]
EMBED (Par[t])
new_par_v(_ctx, #{item}, _enc__type_t);
END
end
fun filterL[linear a](fn : borrowed a -> bool, ps : Par[a]) : Par[a]
joinL(ps >> fun (item : borrowed a)
if fn(item) then
liftvL(item)
else
emptyL[a]()
end
end)
end this code from above does not compile. fun liftvL[linear t](item: borrowed t): Par[t]
EMBED (Par[t])
new_par_v(_ctx, #{item}, _enc__type_t);
END
end the typechecker now complains that:
If you add the
the typechecker complains that:
I don't think I can get passed this last error. In any case, this suggests that I need to have mostly three different implementations of any combinator, e.g.
|
When do you need to implement 1? Unless you are going to save the argument on the heap or send it to a different actor you might as well let it be It does seem however like your problem would be solved if there was a way to abstract over Actually, when trying this out it seems like this is already the case!
I could rewrite your filter function using tons of stubs (and sidestepping some other bugs I ran into):
Note that the |
Hi,
I was trying to use a simple high-order function but I am not sure I got this correctly. The original function is here:
However, I need to work with
linear a
;I have added thelinear a
type variable to the function and I also also use a borrow block in the internal function to be able to alias the linear item; after the borrow block I expected to get back my normal linear item:However, this throws the typing error:
Since it does not allow me to use the function
fn
without adding theborrowed
annotation, an internal detail in the implementation pollutes the top level signature of the function. The end result is:This however does not compile because the type parameter
a
inps >> fun (item : a)
now needs to have theborrowed
annotation as well. Ok, so I update the code to (addition ofborrowed
in the lambda function):Now, it complains that
liftvL
:I do understand the message but at this pace, a combinator that wants to work with
read
andlinear
modes needs to implement at least three functions:sharable
annotation forread
My questions given the reasoning above are:
filter
combinator that would give me the semantics that I want?linear borrowed
annotation. However, for functions, isn't this exposing and tying the internal implementation details to top level types?The text was updated successfully, but these errors were encountered: