元组和功能组成 [英] Tuple and function composition

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

问题描述

有没有更好的方法来表示带有函数组合的(\(a,b) - > a< b)?我觉得我错过了一些东西,尝试咖喱只会让我更困惑。

解决方案

curry 在这里使用是错误的;它将一个在元组上运行的函数转换成一个curried函数。你需要相反的,这是 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屋!

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