Dot operator in haskell with multi-parameter functions

I want to write a point-free function in haskell so that everything is simple, let's say I want to make this function:

maxmin :: Ord a => a -> a -> a -> a maxmin abc = max a (min bc) 

I can improve it to

 maxmin ab = (max a) . (min b) 

but is there a way to get rid of a and b?

+6
source share
2 answers

I would not say that it is easier, but here you go:

 maxmin :: Ord a => a -> a -> a -> a maxmin = (. min) . (.) . max 

(Generated using the pl tool from lambdabot http://www.haskell.org/haskellwiki/Pointfree )

 lambdabot> pl maxmin abc = max a (min bc) maxmin = (. min) . (.) . max 
+8
source

You just use the "three section laws" to do this,

 (a `op` b) = (a `op`) b = (`op` b) a = op ab 

so that

 import Control.Arrow maxmin ab = (max a) . (min b) = (.) (max a) (min b) = uncurry (.) (max a, min b) = uncurry (.) . (max *** min) $ (a, b) = curry (uncurry (.) . (max *** min)) ab 

which also cannot be read. :)

+3
source

All Articles