@ Miguel: Thanks for carrying out the fixpoint computation I was too
lazy to do! I see: lazy evaluation programmers must not be lazy ;-)
@ Josef: Oh yes, I mixed up x and y! In fact, I was confused about the
semantical difference between eqrev and eqrev', although eqrev is just
an iterative version of eqrev' -- if x and y were not mixed up.
Peter
Peter Padawitz wrote:
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,[])
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe