Dot operator in haskell with multi-parameter functions

前端 未结 2 628
北海茫月
北海茫月 2021-01-01 00:12

I want to write a function point-free in haskell, to keep things simple lets say I want to make this function:

maxmin :: Ord a => a -> a -> a ->          


        
2条回答
  •  独厮守ぢ
    2021-01-01 00:42

    You just use the "three laws of sections" for that,

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

    so that

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

    which is not too readable either. :)

提交回复
热议问题