I know that in Haskell, there is a awesome feature called function composition so that we could make our Haskell code pithier, like:
(f . g) x
instead of f (g x)
, foo x $ bar y z
instead of foo x (bar y z)
But is it possible that we could use function composition for foo (bar x) (bar y)
?
You can use the on
function for this, for instance
import Data.Function
data Person = Person{name::String, age::Int}
compare `on` age --same as `\x y -> compare (age x) (age y)`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With