Seeing and Doing : Example :
Sorting efficiently with structural recursion
We combine quicksort
and filter
into one function:
qsf p xs = quicksort (filter p xs)
By simple transformations, we obtain:
qsf p [] = []
qsf p (x:xs) = if p x
then qsf (\x'->p x' && x'<x) xs++
x:
qsf (\x'->p x' && x'>=x) xs
else qsf p xs
We used the law:
filter p1 . filter p2 === filter (\x->p2 x && p1 x)