I want to write a function that checks if two lists are "almost" equal. The first parameter d
is used for precision - the difference between the elements must not exceed d
.
For example, nearlyEqual 0.5 [2,5] [2.5, 5.1]
equals True
, but nearlyEqual 0.1 [2,5] [2.5, 5.1]
equals False
.
I wrote this but it is not working:
nearlyEqual :: Int -> [Int] -> [Int] -> Bool
nearlyEqual d xs ys = foldr(&&) True $ zipWith (\x y -> abs(x-y)<=d)
What am I missing? Any help would be greatly appreciated!