On Github tyukiand / scavenger_presentation
Andrey Tyukin, 2015-07-22
Suppose that we have an algorithm: Preprocessing, Core algorithm, Posprocessing
Multiple variants of each sub-algorithm
How do we specify the jobs? Jobs are represented by instances of the Computation[X]-trait
// Scala code
trait Computation[+X] {
def identifier: Identifier[X]
def compute(ctx: Context): Future[X]
...
}
trait Future[+X] {
def map[Y](f: X => Y): Future[Y]
def flatMap[Y](f: X => Future[Y]): Future[Y]
...
}
// Will eventually return a list of website addresses
val listOfUrls: Future[JSON] =
myClient.getJson("www.google.com/api/findMePagesWith=JGU")
// Will eventually return page content
val content: Future[String] = addr.flatMap{ json =>
val url = json.get(0).get("url")
myClient.getHtml(url)
}
content.map{ c => println(c) }
We use a separate little language (elements of a free Cartesian closed category) as identifiers. Thus, we can describe function compositions, products, partial applications etc. in a way that can be used by the framework for planning of a good execution order.
// `o` denotes composition
// [-,-] denotes product of morphisms
a = A o [f,g] o (x, y)
b = B o [f,h] o (x, y)
Our identifiers are clever enough to recognize that we need
`f(x)` in both `a` and `b`.
// `o` denotes composition
// `Lambda` denotes currying
// `[-,-]` denotes product of morphisms
// `Fst` and `Snd` are canonical projections
a = Lambda(f o [ Snd, Fst ])(y)(x)
b = f((x,y))
Our identifiers allow the framework to recognize that `a = b`.
This frequently occurs when using partial application.
The API:
We have implemented a framework that
Todo's: