Last active
August 28, 2017 08:30
-
-
Save sjoerdvisscher/ae6c334a6df921fdf20f807332be1137 to your computer and use it in GitHub Desktop.
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
runAdicity_0_1 :: (() -> (a, ())) | |
-> a | |
runAdicity_0_1 f = fst (f ()) | |
adicity_0_1 :: a | |
-> t -> (a, t) | |
adicity_0_1 x t = (x, t) | |
adicity_1_1 :: (a -> b) | |
-> (a, t) -> (b, t) | |
adicity_1_1 f (a, t) = (f a, t) | |
adicity_2_1 :: (a -> b -> c) | |
-> (a, (b, t)) -> (c, t) | |
adicity_2_1 f (x, (y, t)) = (f x y, t) | |
-- | | |
-- >>> (+1) . (*2) $ 3 | |
-- 7 | |
-- >>> (+1) $ (*2) 3 | |
-- 7 | |
-- >>> example1 | |
-- 7 | |
example1 :: Int | |
example1 = runAdicity_0_1 | |
$ adicity_1_1 (+1) . adicity_1_1 (*2) . adicity_0_1 3 | |
-- | | |
-- >>> (+) (2 * 3) 4 | |
-- 10 | |
-- >>> ((+) . (* 2)) 3 4 | |
-- 10 | |
-- >>> example2 | |
-- 10 | |
example2 :: Int | |
example2 = runAdicity_0_1 | |
$ adicity_2_1 (+) . adicity_2_1 (*) | |
. adicity_0_1 2 . adicity_0_1 3 . adicity_0_1 4 | |
main :: IO () | |
main = do print example1 | |
print example2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment