小编Lin*_* Su的帖子

如何在haskell中编写嵌套的if语句?

我有这个函数"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)

haskell

6
推荐指数
1
解决办法
535
查看次数

如何将两个字符串连接在一起?

我有两个这样的字符串:

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)

即:成为一个字符串,它们之间有一条新行.怎么做?

python string

3
推荐指数
2
解决办法
3万
查看次数

如何在scala中将列表元素写入文件?

我有一个列表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)

但是,它没有写任何东西.这是为什么 ?

scala

1
推荐指数
1
解决办法
1388
查看次数

在函数haskell中获取类型错误

我有这些函数,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)

haskell

0
推荐指数
1
解决办法
57
查看次数

如何从scala中的字符串中打印特定数量的单词?

我有一个字符串:

str = "this is a great place...."
Run Code Online (Sandbox Code Playgroud)

我想从这个字符串中只打印30个单词.怎么做?

string scala

-3
推荐指数
1
解决办法
141
查看次数

标签 统计

haskell ×2

scala ×2

string ×2

python ×1