-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
Pipe operator support #91
Conversation
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 think this is a good step forward to get things working, great job!
stdlib/caramel_runtime.erl
Outdated
@@ -16,3 +17,5 @@ recv(Timeout) -> | |||
|
|||
binary_concat(A, B) when is_binary(A) and is_binary(B) -> | |||
<< (A)/binary, (B)/binary >>. | |||
|
|||
pipe(A, B) -> B A. |
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.
pipe(A, B) -> B A. | |
pipe(A, B) -> B(A). |
I think Erlang needs the parentheses here :)
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.
$ erl
1> F = fun (X) -> X + 1 end.
#Fun<erl_eval.44.79398840>
2> F(1).
2
3> F 1.
* 1: syntax error before: 1
3> F 1 .
* 1: syntax error before: 1
3>
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.
Good work! 🤩
Looks good to me. We should be able to optimize the pipe away later on.
stdlib/caramel_runtime.ml
Outdated
@@ -3,3 +3,5 @@ external recv_with_timeout : int -> 'a = "recv" | |||
external recv_and_wait : unit -> 'a = "recv" | |||
|
|||
external ( ^ ) : string -> string -> string = "binary_concat" | |||
|
|||
external ( |> ) : 'a -> 'b -> 'c = "pipe" |
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.
external ( |> ) : 'a -> 'b -> 'c = "pipe" | |
external ( |> ) : 'a -> ('a -> 'b) -> 'b = "pipe" |
This should be a stricter signature that matches what we want out of this operator.
Another thought I had is that we may want to just rewrite the pipes into SSA so we minimize the amount of fun allocations too. So we'd go from this: let f x = x |> add 1 |> div 2 |> mult 3 To this: f(X) ->
Caramel@Tmp1 = add(1, X),
Caramel@Tmp2 = div(2, Caramel@Tmp1),
Caramel@Tmp3 = mult(3, Caramel@Tmp2). This rewrite would be an optimization during translation that happens the moment we find a It also means we can take our time to work out the quirks of partial application in the presence of optional and named arguments as pointed out here: https://github.com/AbstractMachinesLab/caramel/pull/92/files#r605967813 @ayshiff would you be interested in trying this approach? 🙌🏽 |
Yes, absolutely! I am interested in trying this 👍 |
Hey @Ostera @michallepicki 👋 https://github.com/ayshiff/caramel/tree/feature/pipe-operator-test I also have a question about testing. |
Hi! 👋🏽 since I'm currently not working on and have no plans to continue working on this version of the compiler, I'll close this PR. Thanks a lot for your contribution 🙏🏽 |
Closes #72
This PR adds pipe operator support (
|>
).It is in Draft because we have to wait for #44 to be resolved first. (As mentionned here)