Created
April 13, 2012 20:20
-
-
Save gseitz/2379907 to your computer and use it in GitHub Desktop.
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
trait PolyParse[F[_]] { | |
def F: Functor[F] | |
def APP: Applicative[F] | |
def ALT: Alternative[F] | |
def C: Commitment[F] | |
def M: MonadFail[F] | |
} | |
def oneOf[FA](fas: List[FA])(implicit U: Unapply[PolyParse, FA]): U.M[U.A] = fas match { | |
case Nil => U.TC.M.fail[U.A]("failed to parse any of the possible choices".toList) | |
case (f :: fs) => U.TC.ALT.<|>(U.apply(f), oneOf(fs)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment