Skip to content

Conversation

@Sporarum
Copy link
Contributor

@Sporarum Sporarum commented Jun 26, 2023

Compiling the code on latest main gives:

{
  val x = f(x: Int, y => // Recursive value x needs type
    x * (
      y + 1
    ) +
    (x +
    x)
  )
}

Which makes sense as we basically write val x = f(x)

@Sporarum Sporarum changed the title Fix example that did not compile, and following paragraph Fix example that did not compile and following paragraph Jun 26, 2023
@Sporarum Sporarum requested a review from bishabosha June 26, 2023 14:21
@bishabosha
Copy link
Member

does this have an issue that should be linked?

{
val x = f(x: Int, y =>
val x = 4
f(x: Int, y =>
Copy link
Contributor

Choose a reason for hiding this comment

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

As a neophyte, I can't tell if : Int is intended.

It would be poetic justice to val x = 3. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It works because for example val y = x: Int is valid, it widens the type of the expression to Int

And since you can use arbitrary expressions as parameters, val y = f(x: Int) is valid

Copy link
Contributor

@som-snytt som-snytt Jun 26, 2023

Choose a reason for hiding this comment

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

Rephrasing: as a neophyte, : Int is confusing to me. What is it an example of? What does it illustrate? There is no definition of f, is that correct? Therefore, it is not a cut/paste example. Of course, the language reference is permitted to be arbitrarily obscure.

Edit: I should have added, I have no inner need to be right here or to be heard.

Copy link
Member

Choose a reason for hiding this comment

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

I thought it was some way to illustrate that the parser isn't treating the argument list like 2 lambda parameters? but its strange to use it there. It probably shouldn't be there unless it specifically illustrates something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I 100% agree, I didn't change it because I wanted this PR to be minimal

I did not look at other parts of this page than the examples either, there might be other improvements possible

@Sporarum
Copy link
Contributor Author

does this have an issue that should be linked?

Sorry I updated the post to give a bit more context, I discovered this while making #18066

@bishabosha bishabosha merged commit 294b5da into language-reference-stable Jun 27, 2023
@bishabosha bishabosha deleted the Sporarum-patch-1 branch June 27, 2023 08:27
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