Skip to content

Instantly share code, notes, and snippets.

View Krasnyanskiy's full-sized avatar

Sasha Krasnyanskiy

  • Cupertino, California
View GitHub Profile
@Krasnyanskiy
Krasnyanskiy / crdt.md
Created December 7, 2015 14:52 — forked from stonegao/crdt.md

CvRDTs are as general as they can be

What are you talking about, and why should I care?

Now that we live in the Big Data, Web 3.14159 era, lots of people want to build databases that are too big to fit on a single machine. But there's a problem in the form of the CAP theorem, which states that if your network ever partitions (a machine goes down, or part of the network loses its connection to the rest) then you can keep consistency (all machines return the same answer to

@Krasnyanskiy
Krasnyanskiy / ContextBounds.md
Last active December 18, 2015 13:50
-scala: context bound

Context Bounds это синтаксических сахар для неявного списка параметров. Например, такой код

def foo[A : B : C](a: A)

не что иное как

def foo[A](a: A)(implicit evidence: B[A], C[A])

Если есть множественные границы контекста численностью от 1 до N, то они будут транслироваться в один список, как показано выше.

@Krasnyanskiy
Krasnyanskiy / views.scala
Created December 18, 2015 13:56 — forked from vkostyukov/views.scala
Fancy implicit views
trait %>[From, To] {
def apply(x: From): To
}
def view[From, To](f: From => To): From %> To =
new %>[From, To] {
def apply(x: From): To = f(x)
}
implicit i: Int %> String = view(_.toString)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import scalaz._
import scalaz.std.list._
import scalaz.syntax.monad._
import scalaz.syntax.monoid._
import scalaz.syntax.traverse.{ToFunctorOps => _, _}
class Foo[F[+_] : Monad, A, B](val execute: Foo.Request[A] => F[B], val joins: Foo.Request[A] => B => List[Foo.Request[A]])(implicit J: Foo.Join[A, B]) {
def bar: Foo[({type l[+a]=WriterT[F, Log[A, B], a]})#l, A, B] = {
type TraceW[FF[+_], +AA] = WriterT[FF, Log[A, B], AA]
@Krasnyanskiy
Krasnyanskiy / IndexedState.md
Created March 13, 2016 20:52 — forked from pthariensflame/IndexedState.md
An introduction to the indexed state monad in Haskell, Scala, and C#.

The Indexed State Monad in Haskell, Scala, and C#

Have you ever had to write code that made a complex series of succesive modifications to a single piece of mutable state? (Almost certainly yes.)

Did you ever wish you could make the compiler tell you if a particular operation on the state was illegal at a given point in the modifications? (If you're a fan of static typing, probably yes.)

If that's the case, the indexed state monad can help!

Motivation

@Krasnyanskiy
Krasnyanskiy / IndexedCont.md
Created March 13, 2016 20:52 — forked from pthariensflame/IndexedCont.md
An introduction to the indexed continuation monad in Haskell, Scala, and C#.

The Indexed Continuation Monad in Haskell, Scala, and C#

The indexed state monad is not the only indexed monad out there; it's not even the only useful one. In this tutorial, we will explore another indexed monad, this time one that encapsulates the full power of delimited continuations: the indexed continuation monad.

Motivation

The relationship between the indexed and regular state monads holds true as well for the indexed and regular continuation monads, but while the indexed state monad allows us to keep a state while changing its type in a type-safe way, the indexed continuation monad allows us to manipulate delimited continuations while the return type of the continuation block changes arbitrarily. This, unlike the regular continuation monad, allows us the full power of delimited continuations in a dynamic language like Scheme while still remaining completely statically typed.

@Krasnyanskiy
Krasnyanskiy / Product.scala
Last active April 2, 2016 18:34
-scala: comb-s
/**
* @author Alexander Krasniansky
*/
object Product extends App {
def cardinality(set: Set[_]) = set size
// ================= Set Intersection =================
val A = Set(1, 2, 3, 4, 5)
@Krasnyanskiy
Krasnyanskiy / Example.scala
Last active April 3, 2016 20:55
-scala: type classes?
trait A {
def foo()
}
trait B {
def bar()
}
trait C {
self: A with B =>