String 将单词列表转换为字符串的Haskell函数

String 将单词列表转换为字符串的Haskell函数,string,list,haskell,String,List,Haskell,例如: wordsToString ["all","for","one","and","one","for","all"] "all for one and one for all" 我的代码在没有类型声明的情况下工作: wordsToString [] = "" wordsToString [word] = word wordsToString (word:words) = word ++ ' ':(wordsToString words) 但是当我做类型检查时,它显示了一个字符列表,这在

例如:

wordsToString ["all","for","one","and","one","for","all"]
"all for one and one for all"
我的代码在没有类型声明的情况下工作:

wordsToString [] = ""
wordsToString [word] = word
wordsToString (word:words) = word ++ ' ':(wordsToString words)
但是当我做类型检查时,它显示了一个字符列表,这在我看来是错误的,因为我应该将输入声明为字符串列表,并将字符串作为输出:

*Main> :type wordsToString
wordsToString :: [[Char]] -> [Char]
我想将声明更改为
wordsToString::[(String)]->[String]
,但它不起作用

我想将声明更改为
wordsToString::[(String)]->[String]
,但它不起作用

否,您要将声明更改为
wordsToString::[String]->String
。您没有得到字符串列表,只有一个字符串

我想将声明更改为
wordsToString::[(String)]->[String]
,但它不起作用


否,您要将声明更改为
wordsToString::[String]->String
。您没有得到字符串列表,只有一个字符串。

该函数称为
concat

concat :: Foldable t => t [a] -> [a]
concat xs = foldr (++) [] xs
在本例中,您希望在字符之间插入空格。此函数称为插入:

intercalate :: [a] -> [[a]] -> [a]

它是根据
穿插
定义的。该函数称为
concat

concat :: Foldable t => t [a] -> [a]
concat xs = foldr (++) [] xs
在本例中,您希望在字符之间插入空格。此函数称为插入

intercalate :: [a] -> [[a]] -> [a]

它是根据
散布

字符串定义的
只是
[Char]
的类型别名,这意味着它们是完全相同的类型。是什么让你认为
[(String)]->[String]
意味着“一个字符串列表并获取一个字符串作为输出”
String
只是
[Char]
的类型别名,这意味着它们是完全相同的类型。是什么让你认为
[(String)]->[String]
意味着“一个字符串列表并获得一个字符串作为输出”?只要我们建议使用库函数,
unwords
似乎最合适。只要我们建议使用库函数,
unwords
似乎最合适。