Haskell composition (.) vs F#'s pipe forward operator (|>)

前端 未结 10 1630
鱼传尺愫
鱼传尺愫 2020-12-04 07:36

In F#, use of the the pipe-forward operator, |>, is pretty common. However, in Haskell I\'ve only ever seen function composition, (.), being us

10条回答
  •  一个人的身影
    2020-12-04 07:53

    I am being a little speculative...

    Culture: I think |> is an important operator in the F# "culture", and perhaps similarly with . for Haskell. F# has a function composition operator << but I think the F# community tends to use points-free style less than the Haskell community.

    Language differences: I don't know enough about both languages to compare, but perhaps the rules for generalizing let-bindings are sufficiently different as to affect this. For example, I know in F# sometimes writing

    let f = exp
    

    will not compile, and you need explicit eta-conversion:

    let f x = (exp) x   // or x |> exp
    

    to make it compile. This also steers people away from points-free/compositional style, and towards the pipelining style. Also, F# type inference sometimes demands pipelining, so that a known type appears on the left (see here).

    (Personally, I find points-free style unreadable, but I suppose every new/different thing seems unreadable until you become accustomed to it.)

    I think both are potentially viable in either language, and history/culture/accident may define why each community settled at a different "attractor".

提交回复
热议问题