Skip to content

Instantly share code, notes, and snippets.

@dabd
dabd / gist:5902296
Created July 1, 2013 16:22
isomorph flops (1755)
4c3c2c
5c3c2c
6c3c2c
7c3c2c
8c3c2c
9c3c2c
Tc3c2c
Jc3c2c
Qc3c2c
Kc3c2c
5.3.1 Co-Kleisli morphisms
Definition 5.3.5. Let (C, ε, ν) be a comonad on C. A co-Kleisli morphism of C from X to Y is a
morphism CX → Y of C.
Here is a typical situation in science. Suppose that, during an experiment, we have a process
f taking an input x ∈ X and giving an output y ∈ Y. This could be for example a survey in
which we ask people of different age (X) what their political views are (Y). Suppose that we
repeat the experiment, feeding again the same input x to f . It could happen that this time we
get a different outcome than before, y
′ , y. For example, suppose a person of age x expresses
political view y. Another person of the same age x may express a different political view y
trait ActionBuilder2[+R[_]] extends ActionBuilder[R] { self =>
def async2(block: => Task[Result]): Action[AnyContent] =
async(block runAsync)
def async2(block: R[AnyContent] => Task[Result]): Action[AnyContent] =
async(block(_) runAsync)
def async2[A](bodyParser: BodyParser[A])(block: R[A] => Task[Result]): Action[A] =
async(bodyParser)(block(_) runAsync)
error_log /usr/local/var/log/nginx/error.log;
worker_processes 4;
#worker_shutdown_timeout 1s;
events {
worker_connections 4096;
}
implicit def taggedStringFormat[T]: Format[String @@ T] = new Format[String @@ T] {
def reads(json: JsValue): JsResult[String @@ T] = json match {
case JsString(v) => JsSuccess(tag[T](v))
case unknown => JsError(s"String value expected, got: $unknown")
}
def writes(v: String @@ T): JsValue = JsString(v)
}
package models
import org.scalacheck.Arbitrary._
import org.scalacheck.Shapeless._
import org.scalacheck._
import shapeless.tag
import shapeless.tag.{apply => _, _}
object ArbitraryModelsSpecification extends Properties("ArbitraryModelsSpecification") {
import shapeless.tag
import shapeless.tag._
implicit def toTaggedType[U, T](u: U): U @@ T = tag[T](u)
//implicit def toTaggedString[T](s: String): String @@ T = tag[T](s)
trait MyTag
def foo(s: String @@ MyTag): String @@ MyTag = s
import shapeless.tag.@@
import org.scalacheck.Prop.forAll
import org.scalacheck.Shapeless._
trait Baz
case class Foo(s: String @@ Baz)
case class Bar(f: Foo)
import play.api.libs.json.{Format, JsResult, JsValue, Json}
import shapeless.tag.@@
trait Money
case class Amount(price: String @@ Money)
private val amountWrites = Json.writes[Amount]
private val amountReads = Json.reads[Amount]
import org.scalacheck.Arbitrary
import org.scalacheck.Arbitrary._
import org.scalacheck.Gen
def arbitraryCaseClass[A,C](f: A => C)(implicit t: Arbitrary[A]): Arbitrary[C] = Arbitrary(for(v <- arbitrary[A]) yield f(v))
type MyIdType = String
implicit val arbMyIdType: Arbitrary[MyIdType] = Arbitrary(Gen.identifier)