4 ms·
The difference not just a technicality it results in a large difference in readability as it linearises nested calls i.e. it transforms it to a functional pipel
by nicwilson 7y ago
The difference not just a technicality it results in a large difference in readability as it linearises nested calls i.e. it transforms it to a functional pipeline (a la unix pipes).
D has this (called Uniform Function Call Syntax (UFCS) ) and also has optional parenthesis for call with no more arguments which turns this:
send(getInvoice(calculatePrice(x)));
into
x.calculatePrice.getInvoice.send;
It also eliminates the need for extension methods since any function that takes any given type as its first argument is automatically callable as if it were a method of that type, this also applies to templates with the type of the first argument determined by a template parameter.
As for a "wrong way around", you can overdo it both ways, use your judgement. I prefer UFCS for more heavily nested calls which you get when you do a while lot of data transformations all in a row. Some times I use it for a single call but not very often.
- Symmetry 7y agoAnd the weird thing is that it's almost trivial to create an equivalent of (.) in Haskell that's ordered in the more natural forward way and I really wish it was a standard. Though (.) itself does get rid of all those parenthesis.
- echaozh 7y agoAnd reversing the order is also easy. F# has operators going both ways.
- jose_zap 7y agoThat would probably be the (&) operator, which is In the standard library
- Symmetry 7y agoI was thinking more about composition than application. Thankfully, I just remembered that you can use Hoogle to search by type signature so I popped in (a -> b) -> (b -> c) -> a -> c and it directed me to (.>) which is exactly what I was thinking of in the flow package. Flow seems like an interesting package to check out if I ever go and start using Haskell seriously.
- cannabis_sam 7y agoThere is also >>> for left-to-right composition, which is in base. My favorite is Elm, which has |> and <| for application, and >> and << for composition, in the intuitive directions. It makes it easy and natural to eta-reduce/expand, when you want to.