Skip to content
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

Type directed array disambiguation #46

Merged
merged 2 commits into from
Oct 1, 2024

Conversation

goldfirere
Copy link
Contributor

This RFC proposes extending the existing constructor-based type-directed disambiguation mechanism to array literal syntax, in both expressions and patterns. Right now, it would serve only to give literal syntax to floatarrays, but other array constructs seem likely soon (such as immutable arrays or uniform arrays).

@yallop
Copy link
Member

yallop commented Jul 23, 2024

There's some previous discussion under ocaml/ocaml#616, which included array literal disambiguation as part of a larger proposal that included various additional syntactic conveniences (e.g. allowing disambiguation for .() and .()<-, and also using scope to resolve the [||] syntax.)

Regarding the current proposal: I'm in favour. The benefits are fairly limited, but it's forward-compatible with various more interesting things that we might want to do later (e.g. immutable arrays).

@nojb
Copy link

nojb commented Jul 24, 2024

Out of curiosity, I gave it a try: nojb/ocaml@c124bfa. Not sure if the approach is exactly right (comments welcome!), but worked well enough for an experiment:

OCaml version 5.3.0+dev0-2023-12-22
Enter #help;; for help.

# let x = [|1.3; 4.5|];;
val x : float array = [|1.3; 4.5|]
# x.(1);;
- : float = 4.5
# let x : floatarray = [|1.3; 4.5|];;
val x : floatarray = <abstr>
# Float.Array.get x 1;;
- : float = 4.5
# let f = function [|a; b|] -> a + b;;
val f : int array -> int = <fun>
# f [|1;3|];;
- : int = 4
# let f = function [|a; b|] -> a +. b;;
val f : float array -> float = <fun>
# f [|1.;3.|];;
- : float = 4.
# let f : floatarray -> _ = function [|a; b|] -> a +. b;;
val f : floatarray -> float = <fun>
# f [|1.;3.|];;
- : float = 4.
#

@goldfirere
Copy link
Contributor Author

@nojb would you want to open a PR with that implementation? Maybe we can just get this one in. Thanks for taking a stab!

arrays](https://github.com/ocaml/ocaml/pull/13097), and I believe several people
have expressed a desire for compiler support for uniform arrays (which do not
participate in the float-array opimization). (This is just hearsay; I do not
have a reference.) Yet only `array` has first-class syntax, available both for
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A reference on uniform arrays: #37 .

@nojb
Copy link

nojb commented Jul 30, 2024

@nojb would you want to open a PR with that implementation? Maybe we can just get this one in. Thanks for taking a stab!

Yes, I will open a PR soon and it can be discussed there. Thanks.

@nojb
Copy link

nojb commented Jul 30, 2024

@nojb would you want to open a PR with that implementation? Maybe we can just get this one in. Thanks for taking a stab!

Yes, I will open a PR soon and it can be discussed there. Thanks.

See ocaml/ocaml#13340.

@goldfirere
Copy link
Contributor Author

This has now been merged in the compiler. Do we close? Do we merge this? I don't know the protocol.

@gasche
Copy link
Member

gasche commented Oct 1, 2024

We don't have a good protocol for RFCs, the value is in the discussions I think. Merging would make sense, as it keeps a track record of RFCs we have accepted (in practice, if not formally).

@gasche gasche merged commit f3fb455 into ocaml:master Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants