test :: String -> String -> Int
test' x y n = n
test' "" (y:ys) n = error "error"
test' (x:xs) "" n = error "error"
test' (x:xs) (y:ys) n =
if x == y
then test' xs ys n
else test' xs ys (n+1)
test a b = test' a b 0
當我編譯,我得到這樣的輸出:哈斯克爾 - 模式匹配(ES)重疊
Warning: Pattern match(es) are overlapped
得到的答覆永遠是「0」,這是不是我的本意。代碼有什麼問題以及如何解決它?
非常有幫助!我學到了很多!謝謝 – Ferry