mfilter
hintA good first function to write is filtOne, which filters a list based on a single tuple:
> filtOne (3,5) [1..10] [1,2,6,7,8,9,10] > :t filtOne filtOne :: Ord a => (a, a) -> [a] -> [a]Update: Maybe ignore the junk below and consider this: you're almost done! :)
Given filtOne you've then got a choice between a low-tech approach and a high-tech approach.
The low-tech approach: just write a folding function that uses filtOne
The high-tech approach starts by noting that if you fold a list of functions [f1,f2,f3,...fN] with the composition operator you get a function like this:
f1 . f2 . f3 … fNHere's a composeAll function that rolls up a list of functions into a single function.
> let composeAll list = foldl (.) id list > let bigf = composeAll [negate, (*2), (+3)] > bigf 3 -12
In composeAll note that id is the identity function—it simply returns its argument.
Consider making a list of functions where each filters a list of values for one range, like (3,7), and go from there.
Another approach, which is perhaps a poor combination of low-tech and high-tech is to write a custom folding function g such that
foldr g zero [f1,f2,f3,...,fN]produces
f1(f2(f3(...(fN zero))))If you don't see what the zero value would be, let me know.