Skip to content

Instantly share code, notes, and snippets.

@st0012
Last active July 6, 2018 10:38
Show Gist options
  • Save st0012/c28f3d3e101a425657e13fc5c5adb34e to your computer and use it in GitHub Desktop.
Save st0012/c28f3d3e101a425657e13fc5c5adb34e to your computer and use it in GitHub Desktop.
FLOLAC Prerequisites
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