小编sym*_*mon的帖子

Haskell写'\n'而不是换行符

我有这个代码,而不是打印出"\n",我希望它将下一个字符串放在一个新行上,但似乎无法搞清楚.有什么指针吗?

onSeparateLines :: [String] -> String
onSeparateLines [] = ""
onSeparateLines ( x:[] ) = x
onSeparateLines ( x:xs ) = x ++  "\n" ++ onSeparateLines xs
Run Code Online (Sandbox Code Playgroud)

我得到的是

"AAAA\nAAAA"
Run Code Online (Sandbox Code Playgroud)

应该是:

"AAAA"
"AAAA"
Run Code Online (Sandbox Code Playgroud)

string haskell newline

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

定义haskell的平均值

如何在[Float]不使用递归的情况下使用类型定义均值?也给出小数点后两位的答案.我是Haskell的新手,所以任何帮助都会非常感激.即mean :: [Float] -> Float.

因为mean xs = sum xs / length xs,我得到以下内容:

 No instance for (Fractional Int)
   arising from a use of `/' at test.hs:8:10-27
 Possible fix: add an instance declaration for (Fractional Int)
 In the expression: sum xs / length xs
 In the definition of `mean': mean xs = sum xs / length xs
Run Code Online (Sandbox Code Playgroud)

haskell

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

标签 统计

haskell ×2

newline ×1

string ×1