开发者

Looking for function 'a -> 'b -> 'a * 'b

Is there a built-in "make pair" function or operator? I know this is trivial, but开发者_JAVA技巧 it would ease function composition in some cases.

Basically, just

let makePair a b = a, b

Can I also suggest Foogle?


No, I don't think there is a function like that in the F# library (and you also cannot treat , as an operator, which is allowed in Haskell).

F# lacks many other functions that are often used in function composition (or point-free style) including flip : ('a -> 'b) -> 'b -> 'a and curry : ('a * 'b -> c) -> 'a -> 'b - 'c). Frankly, I think that this is a good thing because it discourages people from writing code that is hard to read.

Of course, there are many cases where using some function like this would give readable code, but it is really difficult to find the right ballance.


FSharpx aims to fill some of those gaps (whenever possible). It has flip, curry and tuple constructors (among many other things).

If you're really interested in building Hoogle for F# you could work with Neil Mitchell (creator of Hoogle) to implement it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜