Created
June 26, 2017 03:17
-
-
Save n4to4/4ac017981722a56e193d7f7b5fedcd68 to your computer and use it in GitHub Desktop.
PartialUnification.scala
This file contains hidden or 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
// scalacOptions += "-Ypartial-unification" | |
object Foo { | |
trait KVS[F[_], K, V] { | |
def put(k: K, v: V): F[Unit] | |
def get(k: K): F[Option[V]] | |
} | |
trait Repository[F[_], Id, A] { | |
def query(id: Id): F[Option[A]] | |
def store(a: A): F[A] | |
} | |
def RepositoryKVInterp[F[_], K, V]( | |
kvs: KVS[F, K, V] | |
) = new Repository[F, K, V] { | |
def query(id: K): F[Option[V]] = ??? | |
def store(r: V): F[V] = ??? | |
} | |
def InMemoryKVSInterpreter[K, V]: KVS[State[Map[K, V], ?], K, V] = new KVS[State[Map[K, V], ?], K, V] { | |
type S = Map[K, V] | |
def put(k: K, v: V): State[S, Unit] = State.modify(_ + (k -> v)) | |
def get(k: K): State[S, Option[V]] = State.inspect(s => s.get(k)) | |
} | |
val inMemoryKVSInterp = InMemoryKVSInterpreter[Int, Int] | |
val intp = RepositoryKVInterp(inMemoryKVSInterp) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment