import Control.Category ((.), (<<<), (>>>), Category)
data InvertibleFunction a b = InvertibleFunction (a -> b) (b -> a)
instance Category InvertibleFunction where
(InvertibleFunction b_c c_b) . (InvertibleFunction a_b b_a) = InvertibleFunction (b_c . a_b) (b_a . c_b)
inv (InvertibleFunction x y) = InvertibleFunction y x
add
:: (Num n
) => n
-> InvertibleFunction n n
add x = InvertibleFunction (+x) (\y -> y - x)
class KindaApplicative f where
(<$>) :: f a b -> a -> b
instance KindaApplicative InvertibleFunction where
(InvertibleFunction f _) <$> x = f x
main
= print $ ((inv
(add
2)) <$> 5)
aW1wb3J0IFByZWx1ZGUgaGlkaW5nICgoLikpCmltcG9ydCBDb250cm9sLkNhdGVnb3J5ICgoLiksICg8PDwpLCAoPj4+KSwgQ2F0ZWdvcnkpCgpkYXRhIEludmVydGlibGVGdW5jdGlvbiBhIGIgPSBJbnZlcnRpYmxlRnVuY3Rpb24gKGEgLT4gYikgKGIgLT4gYSkKCmluc3RhbmNlIENhdGVnb3J5IEludmVydGlibGVGdW5jdGlvbiB3aGVyZQogIChJbnZlcnRpYmxlRnVuY3Rpb24gYl9jIGNfYikgLiAoSW52ZXJ0aWJsZUZ1bmN0aW9uIGFfYiBiX2EpID0gSW52ZXJ0aWJsZUZ1bmN0aW9uIChiX2MgLiBhX2IpIChiX2EgLiBjX2IpCgppbnYgKEludmVydGlibGVGdW5jdGlvbiB4IHkpID0gSW52ZXJ0aWJsZUZ1bmN0aW9uIHkgeAoKYWRkIDo6IChOdW0gbikgPT4gbiAtPiBJbnZlcnRpYmxlRnVuY3Rpb24gbiBuCmFkZCB4ID0gSW52ZXJ0aWJsZUZ1bmN0aW9uICgreCkgKFx5IC0+IHkgLSB4KQoKY2xhc3MgS2luZGFBcHBsaWNhdGl2ZSBmIHdoZXJlCiAgKDwkPikgOjogZiBhIGIgLT4gYSAtPiBiCgppbnN0YW5jZSBLaW5kYUFwcGxpY2F0aXZlIEludmVydGlibGVGdW5jdGlvbiB3aGVyZQogIChJbnZlcnRpYmxlRnVuY3Rpb24gZiBfKSA8JD4geCA9IGYgeAogIAptYWluID0gcHJpbnQgJCAoKGludiAoYWRkIDIpKSA8JD4gNSkK