Created
February 8, 2017 13:36
-
-
Save gdevanla/e57fd7c7be115068a355e0c2765714e5 to your computer and use it in GitHub Desktop.
example of folding over functions
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
-- continuation calling style of functions | |
f :: forall a. Integral a => a -> (a -> a) -> a -> a | |
f y fun x = if x == y then x * x else fun x | |
f_base :: forall a. Num a => a -> a | |
f_base x = x * 100 | |
f2 :: (Integer -> Integer) -> Integer -> Integer | |
f2 = f 2 | |
f3 :: (Integer -> Integer) -> Integer -> Integer | |
f3 = f 3 | |
f4 :: (Integer -> Integer) -> Integer -> Integer | |
f4 = f 4 | |
runF :: Integer -> Integer | |
runF = foldl (flip ($)) f_base [f2, f3, f4] | |
runF2 :: Integer -> Integer | |
runF2 = foldr ($) f_base [f2, f3, f4] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment