How can I understand “(.) . (.)”?

前端 未结 5 1881
我寻月下人不归
我寻月下人不归 2020-12-08 00:40

I believe I understand fmap . fmap for Functors, but on functions it\'s hurting my head for months now.

I\'ve seen that you can just apply the definitio

5条回答
  •  没有蜡笔的小新
    2020-12-08 01:07

    It's easiest to write equations, combinators-style, instead of lambda-expressions: a b c = (\x -> ... body ...) is equivalent to a b c x = ... body ..., and vice versa, provided that x does not appear among {a,b,c}. So,

    -- _B = (.)  
    
    _B f g x = f (g x)
    _B _B _B f g x y = _B (_B f) g x y
                     = (_B f) (g x) y
                     = _B f (g x) y
                     = f ((g x) y)
                     = f (g x y)
    

    You discover this if, given f (g x y), you want to convert it into a combinatory form (get rid of all the parentheses and variable repetitions). Then you apply patterns corresponding to the combinators' definitions, hopefully tracing this derivation backwards. This is much less mechanical/automatic though.

提交回复
热议问题