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

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -