- 寫返回一個列表中的位置的索引位置計數狀態,哈斯克爾
的功能 - 在列表中的指定元素的元素。例如:
- I:位置4 [1,4,3,7,4,2]
- O:[2,5]
pos element list = func element list 0
func :: [a] -> [a] -> [Int] -> [a]
func _ [_] _ = []
func element (x:xs) cont | x==element = cont:func element xs cont+1
| otherwise = func element xs cont+1
擲此錯誤:
- Type error in application
*** Expression : x == element
*** Term : x
*** Type : a
*** Does not match : [a]
*** Because : unification would give infinite type
您的元件變量具有類型'[α]'而x具有類型'A',因此它們不能相比。 – Reite
第一個參數不是數組。 –
這是功課嗎? – augustss