Created
January 26, 2018 13:29
-
-
Save wreczek/856946fe65222bdd659094835909e5ba 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
module Calculation | |
(increment, decrement, add, mul, pow) where | |
-- arithmetic operations, additionally give us the | |
-- view of new, undefined numerals | |
increment :: ((a -> b) -> c -> a) -> (a -> b) -> c -> b | |
increment = \g f x -> f(g(f)(x)) | |
decrement :: (((r -> b) -> (b -> c) -> c) -> | |
(t1 -> t2) -> (t3 -> t3) -> t) -> r -> t2 -> t | |
decrement = \a f x -> a(\g h -> h.g$f)(\y -> x)(\y -> y) | |
add :: r -> ((((t2 -> t1) -> t3 -> t2) -> | |
(t2 -> t1) -> t3 -> t1) -> r -> t) -> t | |
add = \f g -> g(increment) $ f | |
mul :: (b -> c) -> (r -> b) -> r -> c -- function composition | |
mul= \f g x -> f . g $ x | |
pow :: a -> (a -> b) -> b -- use the function on the argument | |
pow = \f g -> g $ f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment