Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell: parse error (possibly incorrect indentation or mismatched brackets) with list comprehension

Tags:

haskell

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!

like image 707
Thalatta Avatar asked Aug 07 '13 18:08

Thalatta


1 Answers

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.

like image 187
Tikhon Jelvis Avatar answered Nov 06 '22 23:11

Tikhon Jelvis