SHARE

TWEET

# Untitled

a guest
Jun 14th, 2018
50
Never

**Not a member of Pastebin yet?**

**, it unlocks many cool features!**

__Sign Up__- -- Answers for Prerequisites in FLOLAC 2018
- -- 1) myFst
- myFst :: (a, b) -> a
- myFst (x, _) = x
- -- 2) myOdd
- myOdd :: Int -> Bool
- myOdd n = (mod n 2) /= 0
- -- 3) Answers:
- {-
- (a) Ord is a class of type where any two value in the type can be compared and get result
- as one of {LT, EQ, GT}, i.e. the type is totally ordered.
- qs :: Ord a => [a] -> [a]
- Mean for all type a which is of class Ord, i.e. equipped with a totally ordered relation
- for all of its elements. Function qs can accept a list of type a and produce another list
- of type a.
- (b) The type of (++) is
- (++) :: [a] -> [a] -> [a]
- -- i.e. take two lists of same type a, produce a combined list of same type a.
- But due to type declaration of qs and type inference by Haskell, the type become
- (++) :: Ord a => [a] -> [a] -> [a]
- The functionality of (++) is to append two list and maintain orders of all elements respectively.
- (c) Elements of ys are those elements in xs which are less or equal (<=) to x.
- Elements of zs are those elements in xs which are greater than x.
- (d) The function qs is an implemetation of quick sort.
- Where qs pick one element (the head of the list) then split the tail into two lists where one contains
- less-or-equal elements and the other contains strictly greater ones, the sort two listd recursively.
- (e) Please see following code
- -}
- qs :: Ord a => [a] -> [a]
- qs list = case list of
- [] -> []
- (x:xs) -> let
- ys = [ y | y <- xs, y <= x]
- zs = [ z | z <- xs, x < z]
- in
- qs ys ++ [x] ++ qs zs

RAW Paste Data

We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.