Created
March 19, 2015 15:39
-
-
Save grapefroot/c4fd3f1d38a1996110de to your computer and use it in GitHub Desktop.
haskell stuff
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
import Data.List | |
maximum' :: (Ord a) => [a] -> a | |
maximum' [] = error "maximum of empty list" | |
maximum' [x] = x | |
maximum' (x:xs) = max x (maximum' xs) | |
replicate' :: (Num i, Ord i) => i -> a -> [a] | |
replicate' n x | |
| n <= 0 = [] | |
| otherwise = x:replicate' (n-1) x | |
reverse' :: [a] -> [a] | |
reverse' [] = [] | |
reverse' (x:xs) = reverse' xs ++ [x] | |
repeat' :: a -> [a] | |
repeat' x = x:repeat' x | |
zip' :: [a] -> [b] -> [(a,b)] | |
zip' _ [] = [] | |
zip' [] _ = [] | |
zip' (x:xs) (y:ys) = (x, y):zip' xs ys | |
quicksort :: (Ord a) => [a] -> [a] | |
quicksort [] = [] | |
quicksort (x:xs) = | |
let smallerSorted = quicksort [a | a <- xs, a <= x] | |
biggerSorted = quicksort [a | a <- xs, a > x] | |
in smallerSorted ++ [x] ++ biggerSorted | |
zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c] | |
zipWith' _ [] _ = [] | |
zipWith' _ _ [] = []h | |
zipWith' f (x:xs) (y:ys) = f x y : zipWith' f xs ys | |
ninetyCCW :: [[Char]] => [[Char]] | |
ninetyCCW x = reverse (transpose x) | |
ninetyCW :: [[Char]] => [[Char]] | |
ninetyCW x = transpose (reverse x) | |
oneEighty :: [[Char]] => [[Char]] | |
oneEighty x = ninetyCCW (ninetyCCW x) | |
reflect :: [[Char]] => [[Char]] | |
reflect x = reverse x | |
reflectHoriz :: [[Char]] => [[Char]] | |
reflectHoriz x = [reverse a | a <- x] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment