Haskell格式化问题 [英] Haskell Formatting Issue

查看:138
本文介绍了Haskell格式化问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

main :: IO ()
main = do 
    contents <- readFile "text.txt"
    let database = (read contents :: [Film])
    putStr "Please enter your username: "
    userName <- getLine
    menu database        
    where menu newDb = do putStrLn "\nPlease select an option:"
                          putStrLn "1: Display all films currently in the database"
                          putStrLn "2: Add a new film to the database"
                          putStrLn "3: Search for films by director"
                          putStrLn "5: Exit"
                          putStr "\nSelected option: "
                          option <- getLine
                          case option of 
                                        "1" -> putStrLn(formatDatabase newDb)
                                        "2" -> do putStr "Name of film: "
                                               title <- getLine
                                               putStr "Name of director: "
                                               director <- getLine
                                               putStr "Year of release: "
                                               year <- getLine
                                               putStrLn(formatDatabase $ addFilm title director (read year) [] newDb)
                                        "3" -> do putStr "Name of director: "
                                               director <- getLine
                                               putStrLn $ formattedByDirector director
                          menu newDb

返回错误:

Returns error:

Parse error in pattern: putStr

On the line: "2" -> do putStr "Name of film: "


推荐答案

您必须缩进在 do >之后的行中的所有行都会阻止所有第一个标记的级别。 。

You must indent the lines in the do block all to the level of the first token after the do. The same applies to the case 3.

case option of 
  "1" -> putStrLn(formatDatabase newDb)
  "2" -> do putStr "Name of film: "
            title <- getLine
            putStr "Name of director: "
            director <- getLine
            putStr "Year of release: "
            year <- getLine
            putStrLn(formatDatabase $ addFilm title director (read year) [] newDb)
  "3" -> do putStr "Name of director: "
            director <- getLine
            putStrLn $ formattedByDirector director

这篇关于Haskell格式化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆