相关疑难解决方法(0)

Haskell:使用`=='时没有(Eq a)的实例

isPalindrome :: [a] -> Bool
isPalindrome xs = case xs of 
                        [] -> True 
                        [x] -> True
                        a -> (last a) == (head a) && (isPalindrome (drop 1 (take (length a - 1) a)))

main = do
    print (show (isPalindrome "blaho"))
Run Code Online (Sandbox Code Playgroud)

结果是

No instance for (Eq a)
  arising from a use of `=='
In the first argument of `(&&)', namely `(last a) == (head a)'
In the expression:
  (last a) == (head a)
  && (isPalindrome (drop 1 (take (length a …
Run Code Online (Sandbox Code Playgroud)

haskell

17
推荐指数
1
解决办法
1万
查看次数

标签 统计

haskell ×1