开发者

howto make a simple selection in haskell?

i have a problem, this code dont work and i dont know why:

foo :: [String] -> IO [Stri开发者_如何学编程ng]
foo input = do
    choice <- getLine
    if choice == "1" then do
        putStrLn "good choice"
        return input
    else
        return []


As is (with a bit of retabbing) the code works for me. if/else is difficult to get correct with the tabs. The Wiki article if/then/else should help.

foo :: [String] -> IO [String]
foo input = do
  choice <- getLine
  if choice == "1" then do
    putStrLn "good choice"
    return input
    else
    return []

Eliminating the inner do expression makes the if/then block a little more easy to indent.

foo2 input = do
  choice <- getLine
  if (choice == "1") 
  then (putStrLn "good choice" >> return input)
  else (return [])
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜