Correct syntax of let ... in and where clauses in Haskell -
i trying declare local variables (is right term in case of haskell?) in haskell using , let-in clauses. whenever clauses longer single line parse errors:
> letexample :: int -> int > letexample 0 = 0 > letexample n = > let 1 = 1 > 4 = 4 > 8 = 8 > in one*four*eight
when trying load above code ghci following error:
letexample.lhs:4:33: parse error in let binding: missing required 'in' failed, modules loaded: none.
i following error when trying load code below:
whereexample:5:57: parse error on input ‘=’ failed, modules loaded: none.
code:
> whereexample :: int -> int > whereexample 0 = 0 > whereexample n = 1 * 4 * 8 > 1 = 1 > 4 = 4 > 8 = 8
what right way of using let , in above cases?
the posted code mixes tabs , spaces. frequent cause of indentation problems.
the haskell report, defined language, states tabs equivalent 8 spaces. if editor configured display tabs number of spaces, chances reading indented @ correct level not compiler.
the easiest fix replace tab spaces in source files. that, recommend turning on warnings passing -wall
flag, or adding
{-# options -wall #-}
at beginning of source files. doing cause ghc warn when tabs detected.
there alternative solutions drastic remove-all-tabs one. there smart ways mix tabs , spaces in "tab-agnostic" way, make code compilable , readable in spite of how many spaces tab equivalent to. while is not popular, such proposals have technical merits.
Comments
Post a Comment