Skip to content

Instantly share code, notes, and snippets.

@joker1007
Created July 17, 2012 11:53
Show Gist options
  • Save joker1007/3129001 to your computer and use it in GitHub Desktop.
Save joker1007/3129001 to your computer and use it in GitHub Desktop.
replicate' :: Int -> a -> [a]
replicate' n x
| n <= 0 = []
| otherwise = x : replicate' (n-1) x
zip' :: [a] -> [b] -> [(a, b)]
zip' [] _ = []
zip' _ [] = []
zip' (x:xs) (y:ys) = (x, y) : zip' xs ys
zip'' :: [a] -> [b] -> [(a, b)]
zip'' = zipWith (,)
elem' :: (Eq a) => a -> [a] -> Bool
elem' _ [] = False
elem' x (y:ys) = x == y || elem' x ys
zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c]
zipWith' _ [] _ = []
zipWith' _ _ [] = []
zipWith' f (x:xs) (y:ys) = f x y : zipWith' f xs ys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment