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. 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. 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.
Try naming it something else.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.