Replies: 1 comment
-
Indeed, which is why this type of coding is typically a bad idea. Use Fantomas or similar means to prevent accidental outdented code. It would be good if the compiler could raise a warning here.
what syntax are you talking about? You mention CEs not being present for
Sorry, you lost me here. The "long return path" as you call it, was just badly indented. Your code should look like this when properly formatted: let f(x: Result<int, string>) =
match x with
| Error _ -> x
| Ok i ->
printfn "Should be OK"
Ok i If you don't write the code properly, there's no clear telling from reading the code, what the scope is. To prevent such errors, tools like Fantomas exist. I can highly recommend it. In the last example, you seem to suggest to use bang-syntax in non-CE code. However, that's a major syntactical change with, I think, little to no benefit. You can use that syntax inside a CE, though. I'm not quite sure what you are trying to achieve here and what |
Beta Was this translation helpful? Give feedback.
-
Though F# is known for not having early returns it actually is capable for this using
if then else
ormatch
expressions when in the first branch the short path returns and in the second the - the longest. From the user point the long execution path might doesn't even look like being in the scope of theelse
branch or last variant ofmatch
which saves the indentation level.Given that F# encourages functional practices but does not provide builtin computation expressions for Result and Option types and that computation expressions of different types are poorly combined with one another and also keeping in mind the successful usage of similar unwrapping syntaxes or special kind of bindings in Rust and Ocaml may we speculate about bringing similar type of syntax in F#?
I imagine that could be in form of the special static method, similar to active pattern that maps the container value into two variants - for short and long return paths and exposes the value from long path for the downstream scope.
The declaration can be like:
On the usage side:
Beta Was this translation helpful? Give feedback.
All reactions