Haskell - 如何嵌套包含多个 putStrLn 语句的多个 if 语句
Haskell - How do I nest multiple if statements containing multiple putStrLn satatements
这是the problem的要点:
check_if_proceed configFolders = do
let emacsdf = "/home/jacek/.emacs.d"
traceM ("calling check_if_proceed " ++ show ("ccc",configFolders))
exists <- doesDirectoryExist emacsdf
symlink <- pathIsSymbolicLink emacsdf
let confemp = configFolders == []
let result = False
if exists
then do
{
if symlink
then do
{
putStrLn ("This action will overwrite the existing symlink\n"++
"poinitng to " ++ "SOMEWHERE-FINISH ME\n\n" )
}
else do
{
putStrLn (emacsdf ++ " is not a symlink\n"++
"to use this utility, in your terminal do soemthing like:\n"++
"$ mv " ++ emacsdf ++ " " ++ emacsdf ++ "-alternative-config\n" ++
"exiting..." )
}
}
else do
{
putStrLn ("no " ++ emacsdf ++ "found in your home folder")
if confemp
then do
{
putStrLn ("nor folders with the alternative emacs config\n" ++
"exiting..." )
}
else
do {
putStrLn "will try to symlink one of the found folders"
}
}
指示如何向其中添加 return 语句的奖励积分。
工作代码
这个 link 显示了一个可以工作的代码,它允许我使用命令式风格探索问题 space。
您缺少 一个 分号,在 line 31 上,在 putStrLn
和 if
之间:
....
else do
{
putStrLn ("no " ++ emacsdf ++ "found in your home folder")
; -- HERE
if confemp
then do
{
putStrLn ("nor folders with the alternative emacs config\n" ++
"exiting..." )
}
....
要遵循的模板是
do { ... ; ... ; ... }
显式大括号 和 分号将防止由于代码中的错误缩进(可能是由于 tabs/spaces 问题)导致的任何解析错误。
完全显式 表示法总是在每个 do
块语句之间使用 ;
。 if ... then ... else ...
弥补了 一个 表达式 / do
语句,即使分布在多行代码中也是如此。
这是the problem的要点:
check_if_proceed configFolders = do
let emacsdf = "/home/jacek/.emacs.d"
traceM ("calling check_if_proceed " ++ show ("ccc",configFolders))
exists <- doesDirectoryExist emacsdf
symlink <- pathIsSymbolicLink emacsdf
let confemp = configFolders == []
let result = False
if exists
then do
{
if symlink
then do
{
putStrLn ("This action will overwrite the existing symlink\n"++
"poinitng to " ++ "SOMEWHERE-FINISH ME\n\n" )
}
else do
{
putStrLn (emacsdf ++ " is not a symlink\n"++
"to use this utility, in your terminal do soemthing like:\n"++
"$ mv " ++ emacsdf ++ " " ++ emacsdf ++ "-alternative-config\n" ++
"exiting..." )
}
}
else do
{
putStrLn ("no " ++ emacsdf ++ "found in your home folder")
if confemp
then do
{
putStrLn ("nor folders with the alternative emacs config\n" ++
"exiting..." )
}
else
do {
putStrLn "will try to symlink one of the found folders"
}
}
指示如何向其中添加 return 语句的奖励积分。
工作代码
这个 link 显示了一个可以工作的代码,它允许我使用命令式风格探索问题 space。
您缺少 一个 分号,在 line 31 上,在 putStrLn
和 if
之间:
....
else do
{
putStrLn ("no " ++ emacsdf ++ "found in your home folder")
; -- HERE
if confemp
then do
{
putStrLn ("nor folders with the alternative emacs config\n" ++
"exiting..." )
}
....
要遵循的模板是
do { ... ; ... ; ... }
显式大括号 和 分号将防止由于代码中的错误缩进(可能是由于 tabs/spaces 问题)导致的任何解析错误。
完全显式 表示法总是在每个 do
块语句之间使用 ;
。 if ... then ... else ...
弥补了 一个 表达式 / do
语句,即使分布在多行代码中也是如此。