T x T -> D
but
T1 x T2 != T2 x T1
def f: A => B = ??? | |
def g: B => C = ??? | |
def h: A => C = g compose f |
def id: A => A = identity | |
// 𝛌(a:A). a |
def f: A => B = { (a:A) => e // e do something with a } | |
// written in 𝛌-calculus style | |
// 𝛌(a:A). e with (e:B) |
trait Cat[->[_, _]] { | |
def id[A]: A -> A | |
def ○[A, B, C]: (B -> C) => (A -> B) => (A -> C) | |
} |
// Yoneda lemma | |
// - Yoneda Embedding is just another case of the lemma | |
// - implies that: | |
// forall r . (a -> r) -> r ≅ a | |
// Any type can be replaced (& back) by a continuation accepting a handler | |
trait Cont[A] { | |
// handler which accepts a A and performs the rest of computation (like returningn a status R) | |
def apply[R](handler: A => R): R | |
} |
package toto | |
object Test { | |
val a = 3 | |
case class Foo(a: String) | |
def f(foo: Foo): String = foo.a | |
} |
// Build Scala source code | |
val tree = q""" | |
object Test { | |
val a = 2 + 5 | |
def f(b: String) = { b + a.toString } | |
} | |
""" | |
val src = List(TreeNode(tree)) | |
// Build Scala target code |
// Experimenting reverse auto-differentiation (which is just a generalized form of back-propagation) with: | |
// - a DSL to build expressions without supposing how it will be differentiated | |
// - values are based on ArrayFire to be able to run on CPU or GPU backends (DSL isn't abstract for values) | |
// - a context of differentiation in which the DSL expression is evaluated & which is stateful to keep track of partial computed values without recomputing everything for each differentiations | |
// Nothing very new here, just playing with those concepts to see Rust behavior in trickier contexts | |
// | |
// Inspired by different projects doing the same: | |
// - autodifferentiation in haskell https://hackage.haskell.org/package/ad | |
// - arrayfire-rust & arrayfire-ml https://github.com/arrayfire/arrayfire-ml |
mapAccumL : Traversable t => (a -> b -> (c, a)) -> a -> t b -> (t c, a) | |
mapAccumL f a1 tb = runState (traverse stateFlip tb) a1 | |
where | |
-- if I comment next line, it compiles OK | |
-- else it fails with : | |
-- | |
-- test.idr:91:37:When checking right hand side of test.mapAccumL, stateFlip with expected type | |
-- StateT a Identity c | |
-- When checking an application of f: |