-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add new undentation rule for match with #833
Comments
Why not:
|
@7sharp9 I updated the examples, I meant this to work for long expressions |
This proposal kind of matches how IF THEN can be structured if
true
then
printfn "Hello World" match
x
with
| ... ->
printfn "Hello World" |
@0x53A exactly, thanks for that addition. |
What about interacting with the existing multiple matches cancelling indents? |
Devils avocado: you could just bind the long expression first:
|
I personally think this is reasonable. @dsyme? |
I prefer @7sharp9's avocado being forced. If you want to avoid naming a variable, the following also happens to work (providing an unindentation too ):- ``long/multi line of code`` |> function
| Foo -> false
| Bar -> true though I'd tend to indent as follows in any case where I would apply this : ``long/multi line of code`` |> function
| Foo -> false
| Bar -> true The above tricks have attractions. In practice, however, simply doing a |
I noticed the indentation rule for |
@bartelink, you probably meant it without the backticks? Like so: long/multi line of code
|> function
| Foo -> false
| Bar -> true This aligns nicely and reads even better if you have multiple chained pipes already in the long line part. It's a common practice in my code, but some might argue that an explicit and indented |
That reads a lot worse to me, I dislike the function keyword as it makes you infer the type rather than explicitly state it as in a match. I feel like the indentation keeps you sane in f#, dropping it is just an excuse for not refactoring into understandable blocks. |
@7sharp9 I don't understand this? Neither of those have an explicit type annotation. And |
The function keyword is like information hiding, it always takes longer to understand the intent, I would be happy with this removed. |
@7sharp9, well, I guess that's a matter of personal taste, then. I don't see it hiding anything, at least not more than, say, piping, or composition (both possible with I think they both have merit. If you have this code: someList
|> List.map someMapper
|> List.tryPick (function Foo _ -> None | Bar x -> Some x)
|> function
| Some _ -> printfn "found"
| None -> printfn "not found" then, writing this be code with In other cases, BTW, this is not to say I'm against the proposal, I support it. Just trying to show the existing options as well. |
If needed, I tend to: match parent.Nodes()
|> Seq.tryFind (fun e -> match e with | :? XElement as e -> e.Name.LocalName = node | _ -> false)
|> next
|> other with
| Some existingNode -> existingNode :?> XContainer
| None -> // .. But yes this feels a bit like an inconsistency, but is it? I tend to agree with @smoothdeveloper and the |
I also don't see 'function' as hiding anything in this case. If you have:
Then that is somewhat hiding that f takes a second argument especially if you're not used to seeing that style. But in the case of piping into a function it seems obvious what's being piped in. I do think it would be more obvious if you could pipe into the match rather than into function, like this:
I've used this form for some code that needed to transform something in multiple steps and it's pleasingly elegant, I like not having to make up names for things for temporary bindings. |
@Happypig375 I've marked this as approved-in-principle (meaning the original suggestion) |
Completed in preview dotnet/fsharp#11772 |
Add new undentation rule for match with
I propose we add a new undentation rule for
The existing way of approaching this problem in F# is quite ugly
or what I catch myself doing a lot without really needing that local at all beyond the match is
Pros and Cons
The advantages of making this adjustment to F# are: easier to use match statements with large expressions
The disadvantages of making this adjustment to F# are: I'm not sure if this would be breaking anything
Extra information
Estimated cost (XS, S, M, L, XL, XXL): XS
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: