import Control.Arrow
-- Arrow style natural numbers by itchyny
toint = ($ ((1+), 0))
tobool = ($ (True, False))
-- Do not use except for
-- fst
-- snd
-- (,)
-- app
-- id
-- (>>>)
-- (&&&)
-- (***)
--
-- and following is allowed
-- (<<<) == flip (>>>)
-- curry == ((<<<) >>> ((,) >>>))
-- flip = uncurry >>> ((snd &&& fst) >>>) >>> curry
--
-- don't use
-- uncurry == (*** id) >>> (>>> app)
-- == \f -> (f *** id) >>> app
-- (.) f g == g >>> f
-- first f == f *** id
-- second g == id *** g
-- ($) == curry app
-- const == ((,) >>> (>>> fst))
-- etc.
-- zero = \(f, x) -> x
-- succ = \n (f, x) -> f (n (f, x))
-- plus = \m n (f, x) -> m (f, (n (f, x)))
-- mult = \m n -> m ((plus n), zero)
mult
= ((plus
>>> (flip (,) zero
)) >>>)
-- pred = \n f x -> n (\g h -> h (g f)) (\u -> x) (\u -> u)
-- true = \(x, y) -> x
-- false = \(x, y) -> y
-- and = \p q -> p (q, false)
-- or = \p q -> p (true, q)
-- not = \p -> p (false, true)
main = do
print $ toint
$ plus five three
print $ toint
$ mult four six
-- print $ toint $ pred six
-- print $ toint $ pred (plus (two six))
aW1wb3J0IFByZWx1ZGUgaGlkaW5nIChzdWNjLCBwcmVkLCBhbmQsIG9yLCBub3QpCmltcG9ydCBDb250cm9sLkFycm93CgotLSBBcnJvdyBzdHlsZSBuYXR1cmFsIG51bWJlcnMgYnkgaXRjaHlueQoKCnRvaW50ID0gKCQgKCgxKyksIDApKQp0b2Jvb2wgPSAoJCAoVHJ1ZSwgRmFsc2UpKQoKLS0gRG8gbm90IHVzZSBleGNlcHQgZm9yCi0tICAgIGZzdAotLSAgICBzbmQKLS0gICAgKCwpCi0tICAgIGFwcAotLSAgICBpZAotLSAgICAoPj4+KQotLSAgICAoJiYmKQotLSAgICAoKioqKQotLQotLSBhbmQgZm9sbG93aW5nIGlzIGFsbG93ZWQKLS0gICAgKDw8PCkgPT0gZmxpcCAoPj4+KQotLSAgICBjdXJy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