Skip to content

Instantly share code, notes, and snippets.

View mandubian's full-sized avatar

Pascal Voitot mandubian

View GitHub Profile
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)
@mandubian
mandubian / Cat.scala
Last active November 11, 2017 14:44
Category
trait Cat[->[_, _]] {
def id[A]: A -> A
def ○[A, B, C]: (B -> C) => (A -> B) => (A -> C)
}
@mandubian
mandubian / yoneda.scala
Created November 3, 2017 16:11
Yoneda Isomorphism between type A and the continuation/handler pattern
// 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
}
@mandubian
mandubian / Test.scala
Last active October 17, 2017 10:54
Scalameta AST diffing enriched by Semantic Database
package toto
object Test {
val a = 3
case class Foo(a: String)
def f(foo: Foo): String = foo.a
}
@mandubian
mandubian / diff-viz.scala
Created October 16, 2017 13:22
Visualizing scala code diff in scala code (result is compiling Scala code with diffs annotated in comments)
// 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
@mandubian
mandubian / gist:1798e91d48835625736622bb1e21798d
Last active October 12, 2017 15:16
Is there a name to this math structure?

D is a product of T but non-commutative

T x T -> D

but

T1 x T2 != T2 x T1
@mandubian
mandubian / diff_prog.rs
Last active August 18, 2017 15:36
Experimenting reverse auto-differentiation with abstract DSL in Rust & ArrayFire (which is just a generalized form of back-propagation)
// 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
@mandubian
mandubian / mapaccuml.idr
Last active March 21, 2017 21:38
why this compile error?
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: