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

前端 未结 10 1627
鱼传尺愫
鱼传尺愫 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 08:08

    Aside from style and culture, this boils down to optimizing the language design for either pure or impure code.

    The |> operator is common in F# largely because it helps to hide two limitations that appear with predominantly-impure code:

    • Left-to-right type inference without structural subtypes.
    • The value restriction.

    Note that the former limitation does not exist in OCaml because subtyping is structural instead of nominal, so the structural type is easily refined via unification as type inference progresses.

    Haskell takes a different trade-off, choosing to focus on predominantly-pure code where these limitations can be lifted.

提交回复
热议问题