Skip to content

Instantly share code, notes, and snippets.

@grapefroot
Created March 19, 2015 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grapefroot/c4fd3f1d38a1996110de to your computer and use it in GitHub Desktop.
Save grapefroot/c4fd3f1d38a1996110de to your computer and use it in GitHub Desktop.
haskell stuff
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