嗨,我自己也搞不懂,我在网上也找不到一个例子
我尝试使用一个可能或一个保护,而我找到的示例只有两个变量,当我编辑或跟踪超过两个变量的示例时,我得到了一个错误,以下是我要做的事情
--maybe example
Fun :: Double -> Double -> Double -> Maybe Double
Fun a b c
| a >= -1.0 || a <= 1.0 || b >= -1.0 || b <=1.0 || c /=0 || c >= -1.0 = Nothing
| otherwise = Just max( ((c^ (-c)) + (a^(-c)-1.0) ^ (a+ (-1.0/a))) 0.0)gchi错误
The function `Just' is applied to two arguments,
but its type `a0 -> Maybe a0' has only one而hlint给出了
No suggestions尝试使用防护时,我得到了一个不同的错误
--guard example
Fun :: Double -> Double -> Double -> Maybe Double
Fun a b c
| a >= -1.0 || a <= 1.0 || b >= -1.0 || b <=1.0 || c /=0 || c >= -1.0 = error "Value out of range "
| otherwise = max( ((c^ (-c)) + (a^(-c)-1.0) ^ (a+ (-1.0/a))) 0.0)下面是ghc和hlints错误
test.hs:10:1:
Invalid type signature: Fun :: Double
-> Double -> Double -> Maybe Double
Should be of form <variable> :: <type>
$ hlint test.hs
Error message:
Left-hand side of type signature is not a variable: Fun
Code:
Fun :: Double -> Double -> Double -> Maybe Double
> Fun a b c发布于 2012-05-25 00:49:47
您必须使用小写字母编写函数。这意味着要这样写:
fun :: Double -> Double -> Double -> Maybe Double
fun a b c ...函数永远不能以大写字母开头,因为大写标识符是为模块(例如Data.List)、类型构造函数和数据构造函数(如Int或Maybe或Just)以及其他一些东西保留的。
Just构造函数的应用程序也有一个问题。如果你这样写:
Just max(something)..。它的意思是一样的:
Just max something也就是说,你给了Just两个参数。你需要通过调整你的括号来解决这个问题:
Just (max something)发布于 2012-05-25 00:51:20
语法错误,主要是:
f :: Double -> Double -> Double -> Maybe Double
f a b c
| a >= -1
|| a <= 1
|| b >= -1
|| b <= 1
|| c /= 0
|| c >= -1
= Nothing
| otherwise
= Just $ max ((c ** (-c)) + (a ** (-c)-1) ** (a+ (-1/a))) 0请注意,在Just包装器中使用了更通用的指数运算符、(**)和$来避免使用max中的括号。
https://stackoverflow.com/questions/10741834
复制相似问题