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

fun arrow placement #1551

Closed
ploeh opened this Issue Sep 19, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@ploeh
Contributor

ploeh commented Sep 19, 2016

Repro steps

Define functions bar and baz. Write the following function foo as follows:

let foo =
    fun x y z
    ->  (x, y)
    ||> bar
    |>  baz z

Expected behavior

I'd like that to compile, if it wouldn't conflict with some other syntax that I can't think of right now.

Actual behavior

The code doesn't compile. The error message is:

error FS0010: Incomplete structured construct at or before this point in lambda expression. Expected '->' or other token.

Known workarounds

It's possible to write the foo function like this:

let foo =
    fun x y z ->
    (x, y)
    ||> bar
    |>  baz z

Related information

Why is this even interesting?

Notice that in the first example that shows desired syntax, the fun arrow (->) is placed on the same line as other 'arrows' (the ||> and |> pipeline operators). This makes the code more readable because it clearly shows how data flows through the system. (For more details, refer to Yan Cui's article Being visually honest with F#).

With the desired syntax, the fun arrow simple becomes one of several arrows used to compose a function.

For the record, I do realise that in this example, I could refactor to this:

let foo x y z =
    (x, y)
    ||> bar
    |>  baz z

Sometimes, however, you can't do that. Consider. as an example, a situation where you need to bind a function to a pre-defined record label:

type Qux<'a, 'b> = { Corge : 'a -> 'a -> 'a -> 'b; Garply : int }

In that case, you'd have to write:

let q = {
    Corge =
        fun x y z ->
        (x, y)
        ||> bar
        |>  baz z
    Garply = 42 }

I think it'd be nice to be able to writ it like this instead:

let q = {
    Corge =
        fun x y z
        -> (x, y)
        ||> bar
        |>  baz z
    Garply = 42 }
@dsyme

This comment has been minimized.

Show comment
Hide comment
@dsyme

dsyme Sep 27, 2016

Contributor

@ploeh This is a feature request. UserVoice please :)

I know you and others hate UserVoice - and that you think it's a sink for this kind of thing - but we do eventually look at every request there, and the number of votes too. And 57 features have been implemented from that site, and another 40 approved :)

Contributor

dsyme commented Sep 27, 2016

@ploeh This is a feature request. UserVoice please :)

I know you and others hate UserVoice - and that you think it's a sink for this kind of thing - but we do eventually look at every request there, and the number of votes too. And 57 features have been implemented from that site, and another 40 approved :)

@dsyme dsyme closed this Sep 27, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment