元组和功能组成 [英] Tuple and function composition
问题描述
有没有更好的方法来表示带有函数组合的(\(a,b) - > a< b)
?我觉得我错过了一些东西,尝试咖喱
只会让我更困惑。
uncurry
:
uncurry ::(a - > b - > c) - > (a,b)→> c
在这种情况下,它是 uncurry(<)
(在元组上编写函数时有用的组合器的另一个有用的源代码是 Control.Arrow
;因为( - >)
是箭头
的实例,您可以读取 abc
为 b - > c
。)
Is there a better way to express (\(a, b) -> a < b)
with function composition? I feel like I'm missing something and experimenting with curry
only confused me more.
curry
is the wrong thing to use here; it turns a function operating on tuples into a curried function. You want the opposite, which is uncurry
:
uncurry :: (a -> b -> c) -> (a, b) -> c
In this case, it's uncurry (<)
.
(Another useful source for combinators useful in writing functions on tuples is Control.Arrow
; since (->)
is an instance of Arrow
, you can read a b c
as b -> c
.)
这篇关于元组和功能组成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!