3 ms·
> The implicit return at the end of a statement for instance make it harder for me to visually parse what's being returned, since I really depend on that keywor
by bmitc 3y ago
> The implicit return at the end of a statement for instance make it harder for me to visually parse what's being returned, since I really depend on that keyword.
Cutting my teeth on Schemes and MLs and now working in Python, I have the complete opposite experience. It's jarring to have to specify return. What else would I want to do at the end of an expression? It seems tautological. The real reason it's there in Python is early return, which is even more dangerous and jarring.
- mihaic 3y agoI know it's not very FP, but you might explicitly not want to return anything and just modify the data.
- bmitc 3y agoThat's perfectly acceptable and expected. F# supports OOP and imperative just as much as it does functional programming. In the case of such functions and expressions, the value returned is of type `unit` with a single value of `()`. In F#, expressions that return `unit` have the value explicitly ignored if they are not the last expression in a code block. Other expressions returning non-`unit` values that aren't at the end of an expression will generate a warning. In such cases, for example where a function performs a required side effect and returns a value other than `()` but you don't need that value, you can use `|> ignore` to get rid of the warning since it says you are explicitly wanting to ignore the returned value.