Created
September 19, 2012 20:27
-
-
Save bblfish/3752051 to your computer and use it in GitHub Desktop.
ClaimMondad version 1 - does not compile
This file contains 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
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,_]] | |
} | |
trait Level | |
object Truth extends Level | |
object PubKeyVerified extends Level | |
trait Claim[S, L <: Level] { | |
protected val statements: S | |
val level: L | |
// you might want a dedicated type for this verification functions | |
// apart from the simple `Function1`... because then your intent will | |
// become clear and you don't get any 'undesired' implicit values | |
def verify[S2, L2 <: Level](implicit verify: Verificator[S, L, S2, L2]): Claim[S2,L2] = { | |
verify(this) | |
} | |
// ... | |
} | |
trait Verificator[S,L<: Level,S2,L2<:Level] { | |
def apply(s: Claim[S,L]): Claim[S2,L2] | |
} | |
trait TrueClaim[S] extends Claim[S,Truth.type] { | |
def st: S = statements | |
} | |
object Claim { | |
implicit val level: Level = Truth | |
// implicit def truth[S](s: Claim[Truth.type,S]) = s.flatMap(s => new TrueClaim[S] { | |
// protected val statements = s | |
// val level = Truth | |
// } | |
// ) | |
implicit def ClaimMonad[L <: Level](implicit lvl: L): Monad[({type f[+a] = Claim[a,L]})#f] = | |
new Monad[({type f[+a] = Claim[a,L]})#f] { | |
def point[A](a: => A) = new Claim[A,L] { | |
protected val statements : A = a | |
val level: L = lvl | |
} | |
def bind[A, B](fa: Claim[A,L])(f: A => Claim[B,L]) = f(fa.statements) | |
} | |
// implicit def truthClaimMonad = ClaimMonad(Truth) | |
// implicit def pubKeyVerifiedClaimMonad = ClaimMonad(PubKeyVerified) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment