Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

One little asInstanceOf, and we can avoid passing the instance of Par…

…sers to parserMonad.
  • Loading branch information...
commit aa80e4792799a509c728eecff771ec74518720e7 1 parent 8bf1d2a
@retronym authored
View
9 core/src/main/scala/scalaz/std/util/parsing/combinator/Parser.scala
@@ -7,10 +7,11 @@ package combinator
import scala.util.parsing.combinator
trait Parsers {
- class ParsersW[P <: combinator.Parsers](val parser: P) {
- type Parser[A] = parser.Parser[A]
+ class ParsersW[P <: combinator.Parsers with Singleton] {
+ type Parser[A] = P#Parser[A]
+ object dummyParser extends combinator.Parsers
def instance: Monad[Parser] = new Monad[Parser] {
- def pure[A](a: => A): Parser[A] = parser.success(a)
+ def pure[A](a: => A): Parser[A] = dummyParser.success(a).asInstanceOf[Parser[A]] // please look the other way!
def bind[A, B](fa: Parser[A])(f: (A) => Parser[B]): Parser[B] = fa flatMap f
}
}
@@ -20,7 +21,7 @@ trait Parsers {
// The return type is Monad[p.type#Parser]
//
// This way seems to work without -Ydependent-method-types, yay!
- def parserMonad[P <: combinator.Parsers](p: P) = new ParsersW[P](p).instance
+ implicit def parserMonad[P <: combinator.Parsers with Singleton] = new ParsersW[P].instance
}
object Parser extends Parsers
View
1  example/src/main/scala/scalaz/example/ParserUsage.scala
@@ -14,7 +14,6 @@ object ParserUsage extends App {
import scalaz.std.List._ // for Traverse[List]
import scalaz.std.util.parsing.combinator.Parser.parserMonad
- implicit val M: Monad[Parser] = parserMonad(testParser)
val sequence: Parser[List[List[String]]] = parsers.sequence
parseAll(sequence, s)
}
Please sign in to comment.
Something went wrong with that request. Please try again.