Can anybody give me a simple explanation why the second definition of a
palindrome checker does not terminate, although the first one does?
pal :: Eq a => [a] -> Bool
pal s = b where (b,r) = eqrev s r []
eqrev :: Eq a => [a] -> [a] -> [a] -> (Bool,[a])
eqrev (x:s1) ~(y:s2) acc = (x==y&&b,r) where (b,r) = eqrev s1 s2 (x:acc)
eqrev _ _ acc = (True,acc)
pal :: Eq a => [a] -> Bool
pal s = b where (b,r) = eqrev' s r
eqrev' :: Eq a => [a] -> [a] -> (Bool,[a])
eqrev' (x:s1) ~(y:s2) = (x==y&&b,r++[y]) where (b,r) = eqrev' s1 s2
eqrev' _ _ = (True,[])
Peter
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe