Skip to content

Instantly share code, notes, and snippets.

@larsrh
Forked from bblfish/RequestHeader.scala
Created September 19, 2012 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larsrh/3752482 to your computer and use it in GitHub Desktop.
Save larsrh/3752482 to your computer and use it in GitHub Desktop.
Claim Monad for X509 Certificates - having trouble running map on it
import java.net.URI
import scalaz.concurrent.Promise
import scalaz._
import Scalaz._
import language.implicitConversions
case class Cert(cn: String, pubKey: BigInt, webids: List[URI] )
trait RequestHeader {
type Certificates = Cert
def cert: Promise[Claim[_,Certificates]]
}
sealed trait Level
object Truth extends Level
object PubKeyVerified extends Level
trait Claim[L <: Level, S] {
protected val statements: S
val level: L
def verify[L2 <: Level, S2](implicit verify: Verificator[L, S, L2, S2]): Claim[L2, S2] = {
verify(this)
}
def st(implicit ev: L =:= Truth.type) = statements
}
trait Verificator[L<: Level,S,L2<:Level,S2] {
def apply(s: Claim[L,S]): Claim[L2,S2]
}
object Claim {
implicit val level: Truth.type = Truth
implicit def unapplyClaim[TC[_[_]], A0 <: Level, B0](implicit TC0: TC[({type λ[α] = Claim[A0, α]})#λ]): Unapply[TC, Claim[A0, B0]] {
type M[X] = Claim[A0, X]
type A = B0
} = new Unapply[TC, Claim[A0, B0]] {
type M[X] = Claim[A0, X]
type A = B0
def TC = TC0
def apply(ma: Claim[A0, B0]) = ma
}
implicit def ClaimMonad[L <: Level](implicit lvl: L): Monad[({type f[+a] = Claim[L, a]})#f] =
new Monad[({type f[+a] = Claim[L, a]})#f] {
def point[A](a: => A) = new Claim[L,A] {
protected val statements : A = a
val level: L = lvl
}
def bind[A, B](fa: Claim[L,A])(f: A => Claim[L,B]) = f(fa.statements)
}
}
object Test {
import Claim._
implicitly[Truth.type]
val m = Monad[({type f[+a] = Claim[Truth.type, a]})#f]
val p = m.point(Cert("Henry Story",BigInt(123456789),List(new java.net.URI("http://bblfish.net/#hjs"))))
val q = p.map(_.cn)
q.st
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment