我的功能是
import System.IO
import Debug.Trace
main :: IO ()
main = do
datei <- openFile "palindrom.txt" ReadMode
palin <- hGetContents datei
putStrLn $ unlines [ check x | x <- lines palin]
check :: String -> String
check x
| null x = ""
| trace ("call check "++ show x) False = x
| x == (reverse x) = if null x then ""
else do x ++ " Palindrom length " ++ show (length x)
我得到了例外Non-exhaustive patterns in the function `check`.
如何匹配字符串以完成模式,我也尝试了空字符串""
,或者我什至无法在 Haskell 中的字符串上使用这种模式?
ps:palindrom.txt是
a
aa
ab
aha
anna
anne
bry
bub