Skip to content

Instantly share code, notes, and snippets.

@sjoerdvisscher
Last active August 28, 2017 08:30
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 sjoerdvisscher/ae6c334a6df921fdf20f807332be1137 to your computer and use it in GitHub Desktop.
Save sjoerdvisscher/ae6c334a6df921fdf20f807332be1137 to your computer and use it in GitHub Desktop.
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