-
-
Save st0012/c28f3d3e101a425657e13fc5c5adb34e to your computer and use it in GitHub Desktop.
FLOLAC Prerequisites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myFst :: (a, b) -> a | |
myFst (a, b) = a | |
myOdd :: Int -> Bool | |
myOdd x = odd x | |
qs :: Ord a => [a] -> [a] | |
qs [] = [] | |
qs (x:xs) = qs ys ++ [x] ++ qs zs | |
where | |
ys = [ y | y <- xs, y <= x ] | |
zs = [ z | z <- xs, x < z ] | |
-- 3) | |
-- a) `Ord` is a typeclass, it defines behavior like `<`. `>=`..etc. a little bit like | |
-- interface in other languages. | |
-- b) `++` is an operator that concates two lists on first list's end. | |
-- c) ys are elements which are smaller or equal to x. zs are elements that are greater than x. | |
-- d) qs is a quick sort function that sorts elements in ascendant order | |
-- e) | |
qs' input = case input of | |
[] -> [] | |
x:xs -> let less = [ y | y <- xs, y <= x ] | |
greater = [ z | z <- xs, x < z ] | |
in qs' less ++ [x] ++ qs' greater |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment