Curry: An Integrated Functional Logic Language
Curry: An Integrated Functional Logic Language
Curry: An Integrated Functional Logic Language
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
A.2 Higher-Order Functions<br />
Here are some “traditional” higher-order functions to show that the familiar functional programming<br />
techniques can be applied in <strong>Curry</strong>. Note that the functions map, foldr, and filter are<br />
predefined in <strong>Curry</strong> (see Appendix B).<br />
-- Map a function on a list (predefined):<br />
map :: (t1->t2) -> [t1] -> [t2]<br />
map f [] = []<br />
map f (x:xs) = f x:map f xs<br />
-- Fold a list (predefined):<br />
foldr :: (t1->t2->t2) -> t2 -> [t1] -> t2<br />
foldr f a [] = a<br />
foldr f a (x:xs) = f x (foldr f a xs)<br />
-- Filter elements in a list (predefined):<br />
filter :: (t -> Bool) -> [t] -> [t]<br />
filter p [] = []<br />
filter p (x:xs) = if p x then x:filter p xs<br />
else filter p xs<br />
-- Quicksort function:<br />
quicksort :: [Int] -> [Int]<br />
quicksort [] = []<br />
quicksort (x:xs) = quicksort (filter ( x) xs)<br />
39