Last active
December 21, 2015 07:59
-
-
Save haiiro-shimeji/6275375 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module Hoge ( | |
fuga | |
) where | |
filter' :: (a -> Bool) -> [a] -> [a] | |
filter' _ [] = [] | |
filter' p (x:xs) = (if p x then (x:) else id) $ filter' p xs | |
chain :: (Integral a) => a -> [a] | |
chain 1 = [1] | |
chain x = x : chain (if even x then x `div` 2 else 3*x+1) | |
fuga = hoge [(2,2)] --runtime error! | |
where hoge xs = map (\(1,b) -> 1 + b) xs | |
map' :: (a -> b) -> [a] -> [b] | |
map' f xs = foldr (\x acc -> f x : acc) [] xs | |
map'' :: (a -> b) -> [a] -> [b] | |
map'' f xs = foldl (\acc x -> acc ++ [f x]) [] xs | |
foldl' :: (a -> b -> a) -> a -> [b] -> a | |
foldl' f acc [] = acc | |
foldl' f acc (x:xs) = foldl' f (f acc x) xs | |
foldr' :: (a -> b -> b) -> b -> [a] -> b | |
foldr' f acc [] = acc | |
foldr' f acc (x:xs) = f x $ foldr' f acc xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment