Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell let syntax not working

Tags:

haskell

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?

like image 395
Timwi Avatar asked Jul 03 '26 07:07

Timwi


1 Answers

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
like image 99
JB. Avatar answered Jul 05 '26 04:07

JB.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!