Haskell syntax for a case expression in a do block -
i can't quite figure out syntax problem case
expression in do
block.
what correct syntax?
if correct example , explain best.
module main main = putstrln "this test" s <- foo putstrln s foo = args <- getargs return case args of [] -> "no args" [s]-> "some args"
a little update. source file mix of spaces , tabs , causing kinds of problems. tip 1 else starting in haskell. if having problems check tabs , spaces in source code.
return (overloaded) function, , it's not expecting first argument keyword. can either parenthesize:
module main import system(getargs) main = putstrln "this test" s <- foo putstrln s foo = args <- getargs return (case args of [] -> "no args" [s]-> "some args")
or use handy application operator ($):
foo = args <- getargs return $ case args of [] -> "no args" [s]-> "some args"
stylewise, i'd break out function:
foo = args <- getargs return (has_args args) has_args [] = "no args" has_args _ = "some args"
but still need parenthesize or use ($), because return takes 1 argument, , function application highest precedence.
Comments
Post a Comment