Skip to content

Instantly share code, notes, and snippets.

@YuRen-tw
Created May 26, 2018 16:16
Show Gist options
  • Select an option

  • Save YuRen-tw/3e2c0fa9f4a36ac22d0da2f041e6676f to your computer and use it in GitHub Desktop.

Select an option

Save YuRen-tw/3e2c0fa9f4a36ac22d0da2f041e6676f to your computer and use it in GitHub Desktop.
FLOLAC 2018 0-p: Prerequisites
{- 1 -}
myFst :: (a, b) -> a
myFst (a, b) = a
{- 2 -}
myOdd :: Int -> Bool
myOdd = (== 1) . flip mod 2
{- 3 -}
{-
(a) Ord 是一個 Typeclass,它規範某個 type 必須要有(全)序關係(有 <=)。
qs 的 type 表示它是一個函數,從 list of type a 到 list of type a,其中 type a 屬於 Ord。
(b) (++) 的 type 是 [a] -> [a] -> [a]。
(++) 的功能是將兩個 list 串接起來。
(c) ys 的元素是 xs 中小於等於 x 的元素;
zs 的元素是 xs 中大於 x 的元素。
(d) qs 的功能是用遞迴的方法對一個 list 做 Quicksort。
-}
{- 3(e) -}
qs' :: Ord a => [a] -> [a]
qs' ws = case ws of [] -> []
(x:xs) -> let ys = [ y | y <- xs, y <= x ]
zs = [ z | z <- xs, x < z ]
in qs' ys ++ [x] ++ qs' zs
@L-TChen
Copy link

L-TChen commented Jul 3, 2018

Excellent!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment