Here are some equations; at least one of them is false. Which are the true ones, and which are false?
map f . take n = take n . map f map f . reverse = reverse . map f map f . sort = sort . map f map f . filter p = map fst . filter snd . map (fork (f,p)) reverse . concat = concat . reverse . map reverse filter p . concat = concat . map (filter p)
Justify your answer for each with an example.
Its a question I got in my assignment. I checked all the equations but all the equations are coming true. I can't find any test case in which any equation is false. Please help me find the equation which is false
f
test function. Did you try something like the sine function for example ?reverse
operate on lists of arbitrary types. Others don't, likesum
that operates only on lists of numbers. The latter case is suspicious, and indeed it would break equations likef . sum = sum . map f
. Try seeing if there are similarly suspicious functions in your homework text.map f . sort = sort . map f
is true for all functionsf
, not just find a functionf
for which it is true. (Either it's true for allf
, or you can find anf
for which it is not true.)f
has the xyz property”. Once you have figured out which of the 6 equations that is, you just need to find one functionf
that does not have the xyz property.map f . sort = sort . map f
does not hold.