[英]Nested Let syntax in haskell confusion
main = let sumSquares = sum (map (^2) [1..100])
squaredSum = sum [1..100] ^ 2
in sumSquares - squaredSum
New to Haskell, so I've been going back through Project Euler. Haskell的新手,所以我一直在回溯Euler项目。 I know my solution is sound, and it works when I don't bother with any lets. 我知道我的解决方案是合理的,并且在我不打扰任何情况下都可以使用。
For some reason, this gives me an error message. 由于某种原因,这给了我一条错误消息。 Can you help? 你能帮我吗? Thank you! 谢谢!
You have chosen to name this term main
, without giving it the correct type. 您已选择将此词命名为main
,而没有为其指定正确的类型。 A Haskell module with a main
term is expected to define it with type IO ()
, but you have given it an expression that looks something like Num a => a
, by virtue of the -
This error happens because Haskell is looking for some sort of way to make IO ..
an instance of Num
, which it isn't. 具有main
项的Haskell模块应使用IO ()
类型定义它,但是您已经给了它一个类似于Num a => a
的表达式-
由于Haskell正在寻找某种排序,因此会发生此错误。使IO ..
成为Num
实例的方式,实际上不是。
Try naming it something else. 尝试命名其他名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.