0
我最近開始學習Haskell和我的程序我收到以下錯誤:哈斯克爾:預計類型:[字符]實際類型:[[字符]
Couldn't match type ‘[Char]’ with ‘Char’
Expected type: [Char]
Actual type: [[Char]]
In the first argument of ‘head’, namely ‘input’
In the first argument of ‘magi’, namely ‘(head input)’
我的代碼如下所示:
vocals = ["a", "e", "i", "o", "u","y"]
vocal o
| elem o vocals == True = True --return true if the letter is a vowel
| elem o vocals == False = False --else false
magi konsonant = [konsonant] ++ "o" ++ [konsonant]
rovarsprak input
|length input == 0 = ""
|length input > 0 && vocal (head input) == False = magi (head input) ++ rovarsprak (tail input)
|length input > 0 && vocal (head input) == True = head input : rovarsprak (tail input)
據我所知,我得到的錯誤是因爲我的輸入頭部函數是[[]]而不是[字符],但我不明白爲什麼頭部輸入是[[char ]。 謝謝!
謝謝你的回答! 但是我不太清楚'vocal = flip elem vocals'這一行是做什麼的? – Sequinex