Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. instance Comp Integer where
  2. comp x y = x - y
  3.  
  4. instance (Comp a) => Comp (Maybe a) where
  5. comp (Just x) (Just y) = comp x y
  6. comp (Just _) Nothing = 1
  7. comp Nothing (Just _) = -1
  8. comp Nothing Nothing = 0
  9.  
  10. quicksort :: Comp a => [a] -> [a]
  11. quicksort [] = []
  12. quicksort (x:xs) = quicksort small ++ (x : quicksort large)
  13. where small = [y | y <- xs, comp x y >= 0]
  14. large = [y | y <- xs, comp x y < 0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement