我有这个函数"path",它有3个参数:
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 …Run Code Online (Sandbox Code Playgroud) 我有两个这样的字符串:
str1 = "my fav fruit apple"
str2 = "my fav vegetable carrot"
Run Code Online (Sandbox Code Playgroud)
我想加入两个字符串成为:
"my fav fruit apple
my fav vegetable carrot"
Run Code Online (Sandbox Code Playgroud)
即:成为一个字符串,它们之间有一条新行.怎么做?
我有一个列表l2,我想将列表元素写入该文件.我这样做:
val fw = new FileWriter("src/results.txt", true) ;
for( k <- 1 to l2.length) {
println(l2(i))
fw.write(l2(i))
i+=1
}
fw.close()
Run Code Online (Sandbox Code Playgroud)
但是,它没有写任何东西.这是为什么 ?
我有这些函数,stackoverflow中的某个人在尝试解释一个概念时告诉我,但是当我尝试运行它时,我遇到了很多错误.
type World = [String]
removeItem :: String -> World -> IO World
removeItem item world = do
if elem item world
then do putStrLn "Item removed."
return $ delete item world
else do putStrLn "No such item - " ++ item
return world
removeTwoItems a b world = do
world1 <- removeItem a world
world2 <- removeItem b world
return world2
look :: World -> IO World
look w = do
putStrLn $ "You see these items here: " …Run Code Online (Sandbox Code Playgroud) 我有一个字符串:
str = "this is a great place...."
Run Code Online (Sandbox Code Playgroud)
我想从这个字符串中只打印30个单词.怎么做?