Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --myApply :: (Num a0) => (a0 -> a0 -> a0) -> [a0] -> a0
- --myApply func list
- -- = func (head list) value
- --where value =
- data Fraction = Fraction { numerator :: Int
- ,denominator :: Int } deriving (Eq)
- addFractions :: Fraction -> Fraction -> Fraction
- addFractions (Fraction ln ld) (Fraction rn rd)
- | rd == ld = Fraction (ln + rn) ld
- | otherwise = Fraction ((ln*rd) + (rn*ld)) newd where
- newd = ld*rd
- instance Show Fraction where
- show (Fraction num denom) = (show num) ++ " / " ++ (show denom)
- qsort :: (Ord a, Num a) => [a] -> [a]
- qsort [] = []
- qsort (pivot:rest) = qsort left ++ [pivot] ++ qsort right
- where left = filter (<pivot) rest
- right = filter (>=pivot) rest
- --combine :: (Ord a, Num a) => [a] -> [a] -> [a]
- --combine lst1 lst2 = let (slst, llst) = if (length lst1 < length lst2) then (lst1, lst2) else (lst2, lst1) in
- zip' :: [a] -> [b] -> [(a, b)]
- zip' _ [] = []
- zip' [] _ = []
- zip' a b = (head a, head b) : zip' (tail a) (tail b)
- zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c]
- zipWith' _ _ [] = []
- zipWith' _ [] _ = []
- zipWith' fnc (x:xs) (y:ys) = fnc x y : zipWith' fnc xs ys
- filter' :: (a -> Bool) -> [a] -> [a]
- filter' _ [] = []
- filter' fnc (x:xs) = body ++ filter' fnc xs where
- body = if fnc x then [x] else []
- collatz :: Integer -> [Integer]
- collatz x = (takeWhile (/=1) $ iterate nval x) ++ [1] where
- nval val
- | val == 1 = 1
- | even val = val `div` 2
- | otherwise = (val * 3) + 1
- maxList :: (Num a, Ord a) => [a] -> a
- maxList xa = foldl max 0 xa
- longestList :: [[a]] -> [a]
- longestList = foldl (\la xa -> if (length xa > length la) then xa else la) []
- -- takes function(acc, curr) default value, list, returns result of acc's type
- foldl' :: (a -> b -> a) -> a -> [b] -> a
- foldl' fn def [] = def
- foldl' fn def (x:xs) = foldl' fn (fn def x) xs
- flip' :: (a -> b -> c) -> (b -> a -> c)
- flip' f = \x y -> f y x
Add Comment
Please, Sign In to add comment