我有這個功能「路徑」這3個參數:如何在haskell中編寫嵌套的if語句?
path::String->String->String->IO()
path place1 dir place2 =
if place1 == "bedroom" && d == 'n' && place2 == "den"
then do
putStrLn "You are in a bedroom with a large, comfortable bed. It has been a long, tiresome day, and you would like nothing better than to go to sleep."
else
if place1 == "bedroom" && d == 'd' && place2 == "bed"
then describe "bed"
else
if place1 == "den" && d == 's' && place2 == "bedroom"
then describe "bedroom"
else
if place1 == "bed" && d == 'u' && place2 == "bedroom"
then describe "bedroom"
else putStrLn "Cannot go there!"
我想知道如何,如果這是具有多個條件和多個if語句的正確方法是什麼?
BTW,它將可能是一個好主意,改變第二個參數的類型,使其比「Char」或「String」更有意義。 – leftaroundabout 2014-11-09 01:10:41