Haskell组合(。)与F#的管道转发运算符(|>) [英] Haskell composition (.) vs F#'s pipe forward operator (|>)

查看:126
本文介绍了Haskell组合(。)与F#的管道转发运算符(|>)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在F#中,使用管道转发操作符 |> 很常见。然而,在Haskell中,我只见过函数组合,(。),正在使用。我了解他们的相关,但是有没有一个语言的原因,没有使用管道转发在Haskell中,或者是别的什么?

我正在一点点我认为 |> 是一个重要的操作符在F#的文化中,也许与Haskell的类似。 F#有一个函数组合操作符<< ,但我认为F#社区倾向于使用

语言差异:我不喜欢这种风格,我们对两种语言都有足够的了解来进行比较,但是可能的普遍化让绑定的规则有很大的不同,以至于影响这一点。例如,我知道在F#中有时会写

  let f = exp 

不会编译,您需要显式的eta转换:

 令fx =(exp)x //或x |> exp 

使其编译。这也使人们远离无点/构图风格,并转向流水线风格。此外,F#类型推断有时需要流水线操作,因此左侧会出现已知类型(请参阅)。



(个人而言,我觉得无点式风格是不可读的,但我想每个新的/不同的东西似乎都是不可读的,除非您习惯于)



我认为两种语言在任何一种语言中都具有潜在的可行性,历史/文化/意外可能会解释为什么每个社区都有不同的吸引力。 >

In F#, use of the the pipe-forward operator, |>, is pretty common. However, in Haskell I've only ever seen function composition, (.), being used. I understand that they are related, but is there a language reason that pipe-forward isn't used in Haskell or is it something else?

解决方案

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".

这篇关于Haskell组合(。)与F#的管道转发运算符(|>)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆