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]
但它不會工作
'String'只是'[Char]'的類型別名,這意味着它們是_exactly_相同的類型。是什麼讓你認爲'[(String)] - > [String]'意味着「字符串列表並獲得一個字符串作爲輸出」? –