简体   繁体   English

Haskell 复杂 Function 类型

[英]Haskell Complex Function Types

A Haskell function I am struggling with has the following type A Haskell function 我挣扎着有以下类型

func1:: (Integer -> Integer -> Integer) -> Integer -> Integer -> Integer

I am unsure of how to handle the Parenthesis piece in the actual implementation.我不确定在实际实现中如何处理括号部分。 I know that a function should be passed into the input in this scenario.我知道在这种情况下应该将 function 传递到输入中。 (Integer -> Integer -> Integer)

When a function is passed to you as a parameter, the only useful thing you can do with it in the end is to call it.当一个 function 作为参数传递给你时,最后你能用它做的唯一有用的事情就是调用它。 That's what functions are for.这就是函数的用途。 That's what they do.他们就是这么做的。

For example, in this case it may look something like this:例如,在这种情况下,它可能看起来像这样:

func1 :: (Integer -> Integer -> Integer) -> Integer -> Integer -> Integer
func1 f a b = f (a*2) (b+5)

Here, the first parameter is named f and it's a function that takes two parameters, both Integer , and returns another Integer - that much is conveyed by its type (Integer -> Integer -> Integer) .在这里,第一个参数名为f ,它是一个 function,它有两个参数,都是Integer ,并返回另一个Integer - 很多是通过它的类型(Integer -> Integer -> Integer)传达的。

The second and third parameters are named a and b respectively, and they're both Integer .第二个和第三个参数分别命名为ab ,它们都是Integer

The body of function func1 consists of calling its function-parameter f , passing it (a*2) and (b+5) as parameters. function func1的主体包括调用其函数参数f ,将(a*2)(b+5)作为参数传递给它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM