Haskell中的通用函数组合 [英] Generic function composition in Haskell

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

问题描述

我正在阅读此处,并且我注意到,对于例如,如果我有以下函数定义:

  a ::整数 - >整数 - >整数
b :: Integer-> Bool

以下表达式为无效

 (b。a)2 3 

组合的功能必须只有一个参数是很奇怪的。

这个限制是因为在Haskell中定义最通用的一个问题还是有其他原因?



我是Haskell的新手,所以我问的也许是无用的问题。 / div>

当您执行 a 2 3 时,您并未将 a 应用于2个参数。实际上,你只是将 a 应用于它的唯一参数,产生一个函数,然后将该函数应用到3.所以你实际上做了2个应用程序。因此,从某种意义上说,你有什么不等于这个:

  a ::(Integer,Integer) - >整数
b ::整数 - >整数
(b。a)(2,3)

您可以这样做,btw

 (b。a 2)3 


I was reading here, and I noticed that, for example, if I have the following function definitions:

a :: Integer->Integer->Integer
b :: Integer->Bool

The following expression is invalid:

(b . a) 2 3

It's quite strange that the functions of the composition must have only one parameter.

Is this restriction because some problem in defining the most generic one in Haskell or have some other reason?

I'm new to Haskell, so I'm asking maybe useless questions.

解决方案

When you do a 2 3, you're not applying a to 2 arguments. You're actually applying a to it's only argument, resulting in a function, then take that function and apply it to 3. So you actually do 2 applications. So in a sense, what you have is not equivalent to this:

a :: (Integer, Integer) -> Integer
b :: Integer -> Integer
(b . a) (2, 3)

You could've done this, btw

(b . a 2) 3

这篇关于Haskell中的通用函数组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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