Skip to content

Instantly share code, notes, and snippets.

@motokiee
Created October 6, 2015 04:20
Show Gist options
  • Save motokiee/a9d19881e4cb2fe9541c to your computer and use it in GitHub Desktop.
Save motokiee/a9d19881e4cb2fe9541c to your computer and use it in GitHub Desktop.
すごいH本の再帰関数あたり #CodePiece
zip' :: [a] ->[b] -> [(a,b)]
zip' _ [] = []
zip' [] _ = []
zip' (x:xs) (y:ys) = (x,y) : zip' xs ys
elem' :: (Eq a) => a -> [a] -> Bool
elem' a [] = False
elem' a (x:xs)
| a == x = True
| otherwise = a `elem'` xs
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let smallOrEqual = [a | a <- xs, a <= x]
larger = [a | a <- xs, a > x]
in quicksort smallOrEqual ++ [x] ++ quicksort larger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment