Difference between revisions of "PFP Laboratory 3"
Jump to navigation
Jump to search
(Created page with "== High-order functions == * Create a function that takes a string and converts all characters to upper case letters. <syntaxhighlight lang="Haskell">allToUpper :: String ->...") |
(No difference)
|
Revision as of 10:11, 29 September 2022
High-order functions
- Create a function that takes a string and converts all characters to upper case letters.
allToUpper :: String -> String
*Main> allToUpper "aAbc"
"AABC"
import Data.Char
allToUpper :: String -> String
allToUpper xs = [toUpper x |x<-xs]
allToUpper' :: String -> String
allToUpper' xs = map toUpper xs
- Implement the
quicksortalgorithm. As a pivot use always the first element in the list. For dividing the list, use the functionfilter.
quicksort :: (Ord a) => [a] -> [a]
*Main> filter (<5) [1..10]
[1,2,3,4]
*Main> quicksort [1,5,3,7,9,5,2,1]
[1,1,2,3,5,5,7,9]