Timwi
Timwi

Reputation: 66573

Haskell let syntax not working

I’m new to Haskell and I’m trying to write a simple program. However, when running the following program:

main = do
    args <- getArgs
    let w = read (args !! 0) :: Integer
    in print w

I get this error message:

file.hs:4:5: parse error on input `in'

The same let syntax works just fine outside of a do statement...

What am I doing wrong?

Upvotes: 3

Views: 272

Answers (1)

JB.
JB.

Reputation: 42094

The let syntax is different when inside a do block. You don't need the in part, the variable scope is automatically the rest of the do block.

In your case:

main = do
    args <- getArgs
    let w = read (args !! 0) :: Integer
    print w

Upvotes: 6

Related Questions