Created
May 18, 2018 13:21
-
-
Save sasdf/54bc8ee6e5a54883d0a0051c5d61be98 to your computer and use it in GitHub Desktop.
FLOLAC '18 preparation answer
This file contains hidden or 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
{- 1 -} | |
myFst :: (a, b) -> a | |
myFst x = fst x | |
{- 2 -} | |
myOdd :: Int -> Bool | |
myOdd x = mod x 2 == 1 | |
{- 3 -} | |
-- (a) Ord is for types that have an ordering. | |
-- | |
-- (b) (++) :: [a] -> [a] -> [a] | |
-- ++ concatenates two list. | |
-- | |
-- (c) ys is a set of all elements smaller than x, | |
-- while zs is a set of all elements larger than x. | |
-- | |
-- (d) qs is quicksort with first element as pivot. | |
-- | |
-- (e) | |
qs' :: (Ord a) => [a] -> [a] | |
qs' xs = | |
case xs of | |
[] -> [] | |
(x:xs) -> | |
let ys = [y | y <- xs, y <= x] | |
zs = [y | y <- xs, y > x] | |
in | |
qs' ys ++ [x] ++ qs' zs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Well done.
To be precise, every instance of
Ord
has a total order provided bycompare:: a -> a -> Ordering
.should be "... smaller than or equal to
x
..."