Skip to content

[style-guide] Multiline application in patterns #717

@nojaf

Description

@nojaf

Hello,

What should the guidance be for multiline (function?) applications in patterns?
Example:

match myString with
| Regex @"^(\w+) can fly (\d+) km/s for (\d+) seconds, but then must rest for (\d+) seconds\.$" [ name; speed; flyTime; restTime ] ->
    ()

Imagine this pattern doesn't respect the max_line_length, how should it be formatted multiline?

This

match myString with
| Regex 
    @"^(\w+) can fly (\d+) km/s for (\d+) seconds, but then must rest for (\d+) seconds\.$" 
    [ name; speed; flyTime; restTime ] ->
    ()

comes to mind.

Related, patterns do seem to have some funky offset rules from time to time.
The same example wrapped in a record:

match myString with
| { X = Regex 
            @"^(\w+) can fly (\d+) km/s for (\d+) seconds, but then must rest for (\d+) seconds\.$" 
            [ name
              speed
              flyTime
              restTime ] } ->
    ()

Notice that:

match myString with
| { X = 
        Regex 
            @"^(\w+) can fly (\d+) km/s for (\d+) seconds, but then must rest for (\d+) seconds\.$" 
            [ name
              speed
              flyTime
              restTime ] } ->
    ()

is invalid F# code. (online tool)

Another interesting case is:

match myString with
| X(
    Regex 
        @"^(\w+) can fly (\d+) km/s for (\d+) seconds, but then must rest for (\d+) seconds\.$" 
        [ name
          speed
          flyTime
          restTime ] 
  ) ->
    ()

This is valid code, thought the closing ) needs to be aligned with the X column.

@dsyme any thoughts on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions