[Haskell-cafe] lazy evaluation
Peter Padawitz
peter.padawitz at udo.edu
Wed Feb 6 08:32:08 EST 2008
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
More information about the Haskell-Cafe
mailing list