Skip to content

Instantly share code, notes, and snippets.

@gdevanla
Created February 8, 2017 13:36
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 gdevanla/e57fd7c7be115068a355e0c2765714e5 to your computer and use it in GitHub Desktop.
Save gdevanla/e57fd7c7be115068a355e0c2765714e5 to your computer and use it in GitHub Desktop.
example of folding over functions
-- 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