I am new to Haskell and am trying to write a simple list comprehension and assign it to a variable. Here is my haskell.hs
file:
--find all multiples of 3 and 5 under 1000
multiples :: [Int]
let multiples = [x | x <- [1..1000], (x `mod` 5 == 0) || (x `mod` 3 == 0)]
then when I try to compile the program with ghc haskell.hs
I get the following error:
haskell.hs:12:1:
parse error (possibly incorrect indentation or mismatched brackets)
Regards!
You have an extra let
. It should be:
multiples :: [Int]
multiples = [x | x <- [1..1000], (x `mod` 5 == 0) || (x `mod` 3 == 0)]
This isn't OCaml, so you don't need let
at the top level.
This might be a little confusing because older versions of GHCi required a let
for defining names. However, this was just a quirk of the interpreter and isn't needed any more with modern GHC versions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With