简体   繁体   English

Haskell咖喱功能和括号

[英]Haskell Curry Function and Brackets

Hi this is probably a very simple problem but I'm having issue with it. 嗨,这可能是一个非常简单的问题,但我对此有疑问。 I'm trying to make a roots function with the formula: 我正在尝试使用以下公式生成根函数:

 roots a b c = ((-b + t)/a', (-b - t)/a')
 where
 t  = b ^ 2 - 4 * a * c
 a' = 2 * a

I'm now trying to make it a curried function however I can't seem to get it to work this is what I've put: 我现在正在尝试使其成为咖喱函数,但是我似乎无法使其正常工作,这就是我所说的:

roots:: Double -> (Double -> (Double -> Double))

Could someone please help me out? 有人可以帮我吗?

Thanks! 谢谢!

In Haskell, functions are automatically curried. 在Haskell中,功能会自动进行处理。 So you don't have to do anything special to make them curried. 因此,您无需做任何特殊的事情即可让他们咖喱。

Your function roots is of the type roots:: Double -> Double -> Double -> (Double, Double) . 您的函数root是roots类型roots:: Double -> Double -> Double -> (Double, Double) Something like this will typecheck: let a = roots 3.0 because of currying. 这样的事情会进行类型检查: let a = roots 3.0原因是因为存在柯里化。

In case your roots function was not curried, then it is likely to have a type like this: roots:: (Double , Double , Double) -> (Double, Double) which is not the proper way to write function definitons. 如果您的roots函数没有被管理,那么它可能具有这样的类型: roots:: (Double , Double , Double) -> (Double, Double)这不是编写函数定义的正确方法。

As far as I know (but I'm not the expert, just had couple of lessons 'bout Haskell so far) function that gets 3 input parameters and produces one output (like in your example) should be written like: 据我所知(但我不是专家,到目前为止只有两节课“关于Haskell”),该函数获取3个输入参数并产生一个输出(如您的示例所示),应这样写:

roots:: Double -> Double -> Double -> Double

Last element in the chain (forth Double) is return type, all previous ones are input parameter types. 链中的最后一个元素(第四个Double)是返回类型,所有先前的元素都是输入参数类型。 This should do the trick 这应该可以解决问题

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

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