Haskell: parsing error (possibly incorrect indentation or inconsistent parentheses) with a list

I am new to Haskell and trying to write a simple understanding of a list 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 a program using ghc haskell.hs , I get the following error:

 haskell.hs:12:1: parse error (possibly incorrect indentation or mismatched brackets) 

Hello!

+6
source share
1 answer

You have an extra let . It should be:

 multiples :: [Int] multiples = [x | x <- [1..1000], (x `mod` 5 == 0) || (x `mod` 3 == 0)] 

This is not OCaml, so you do not need let at the top level.

This can be a bit confusing because older versions of GHCi required let to define names. However, it was just a translator quirk and is no longer needed with modern versions of GHC.

+9
source

Source: https://habr.com/ru/post/951247/


All Articles