Created
December 22, 2014 07:43
-
-
Save JustinSDK/28ca5d1fcdcc7a5fa704 to your computer and use it in GitHub Desktop.
〈Haskell Tutorial(15)Typeclass 定義、實作與衍生〉的答案
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
instance Comp Integer where | |
comp x y = x - y | |
instance (Comp a) => Comp (Maybe a) where | |
comp (Just x) (Just y) = comp x y | |
comp (Just _) Nothing = 1 | |
comp Nothing (Just _) = -1 | |
comp Nothing Nothing = 0 | |
quicksort :: Comp a => [a] -> [a] | |
quicksort [] = [] | |
quicksort (x:xs) = quicksort small ++ (x : quicksort large) | |
where small = [y | y <- xs, comp x y >= 0] | |
large = [y | y <- xs, comp x y < 0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment