Last active
November 13, 2017 14:33
-
-
Save mandubian/1852cd98f20f55c34d5f5b330b56ef3a 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
// a very basic Scala function performing a simple operation on primitive type Int | |
def plus = (x:Int) => (y:Int) => x + y | |
// First, we need to reify our CCC world | |
val K = implicitly[CartesianClosedCat[Function1]] | |
// now we import CCC language into our context | |
import K._ | |
// pseudo-code | |
// we can always uncurry curried function | |
uncurry((x:Int) => (y:Int) => x + y) ≌ (x:Int, y:Int) => x + y | |
// remind projections | |
(x:Int, y:Int) => x ≌ exl[Int, Int] | |
(x:Int, y:Int) => y ≌ exr[Int, Int] | |
// now use product | |
{ (x:Int, y:Int) => x } ⨂ { (x:Int, y:Int) => y } ≌ (x:Int, y:Int) => (x, y) | |
// using projections it can be rewritten | |
exl[Int, Int] ⨂ exr[Int, Int] ≌ (x:Int, y:Int) => (x, y) | |
// now compose with + : (Int, Int) => Int | |
( + ) ○ { (x:Int, y:Int) => (x, y) } ≌ x + y | |
// or | |
plus ≌ ( + ) ○ (exl[Int, Int] ⨂ exr[Int, Int]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment