Home > Software design >  Haskell Indentation Or Mismatched Brackets Error
Haskell Indentation Or Mismatched Brackets Error

Time:09-14

I just started learning haskell and i dont really have too much to say, this is my code:

let issah = "issah"
main = do
    putStrLn(issah)

and it shows this error:

main.hs:3:1: error:
    parse error (possibly incorrect indentation or mismatched brackets)
  |
3 | main = do
  | ^

CodePudding user response:

let clause isn't allowed at the outer level of Haskell file. It is use, either to define local variables within a function or within a do-block. Notice that in gchi you can actually write a top level let. Maybe that's where your confusion comes from

-- no top level let. Just define the constant issah normaly
issah = "issah"
main = do
    putStrLn(issah)

-- let <local variables> in <expression>
main = let issah = "issah" in putStrLn issah

-- let within do block
main = do
   let issah = "issah"
   putStrLn issah

  • Related