Skip to content

Instantly share code, notes, and snippets.

@mykhas
Created April 24, 2017 11:10
Show Gist options
  • Save mykhas/e0f9f12e7ae52f0475e172e0ff0f09f0 to your computer and use it in GitHub Desktop.
Save mykhas/e0f9f12e7ae52f0475e172e0ff0f09f0 to your computer and use it in GitHub Desktop.
fibie :: Integral a => a -> a
fibie a = case a of
0 -> 0
1 -> 1
n -> fibie (n - 1) + fibie (n - 2)
maximum' :: Ord a => [a] -> a
maximum' xs = case xs of
[] -> error "It's empty"
[x] -> x
(x:xs)
| x > maxVal -> x
| otherwise -> maxVal
where maxVal = maximum' xs
replicate' :: (Num a, Ord a) => a -> i -> [i]
replicate' a i
| a <= 0 = []
| otherwise = i:(replicate' (a - 1) i)
take' :: (Num i, Ord i, Eq a) => i -> [a] -> [a]
take' _ [] = []
take' i (first:l)
| i <= 0 = []
| first:l == [] = []
| otherwise = first : take' (i-1) l
reverse' :: [a] -> [a]
reverse' [] = []
reverse' (x:xs) = reverse' xs ++ [x]
repeat' :: a -> [a]
repeat' a = a : repeat' a
zip' :: [a] -> [b] -> [(a, b)]
zip' [] _ = []
zip' _ [] = []
zip' (x:xs) (y:ys) = (x, y) : zip' xs ys
elem' :: (Eq a) => a -> [a] -> Bool
elem' _ [] = False
elem' a (x:xs) = a == x || elem' a xs
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
quicksort [xt | xt <- xs, xt <= x] ++ [x] ++ quicksort [xt | xt <- xs, xt > x]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment