元组和函数组合 [英] Tuple and function composition

查看:29
本文介绍了元组和函数组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有更好的方法来表达 ((a, b) -> a < b) 与函数组合?我觉得我错过了一些东西,而尝试 curry 只会让我更加困惑.

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 在这里用错了;它将对元组进行操作的函数转换为柯里化函数.您想要相反,即 uncurry:

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

在这种情况下,它是 uncurry (<).

In this case, it's uncurry (<).

(用于在元组上编写函数的组合器的另一个有用来源是 Control.Arrow; 因为 (->)Arrow 的一个实例,所以可以阅读 <代码>abc 为 b -> c.)

(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屋!

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