Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…sers to parserMonad.
  • Loading branch information...
commit aa80e4792799a509c728eecff771ec74518720e7 1 parent 8bf1d2a
Jason Zaugg authored October 16, 2011
9  core/src/main/scala/scalaz/std/util/parsing/combinator/Parser.scala
@@ -7,10 +7,11 @@ package combinator
7 7
 import scala.util.parsing.combinator
8 8
 
9 9
 trait Parsers {
10  
-  class ParsersW[P <: combinator.Parsers](val parser: P) {
11  
-    type Parser[A] = parser.Parser[A]
  10
+  class ParsersW[P <: combinator.Parsers with Singleton] {
  11
+    type Parser[A] = P#Parser[A]
  12
+    object dummyParser extends combinator.Parsers
12 13
     def instance: Monad[Parser] = new Monad[Parser] {
13  
-      def pure[A](a: => A): Parser[A] = parser.success(a)
  14
+      def pure[A](a: => A): Parser[A] = dummyParser.success(a).asInstanceOf[Parser[A]] // please look the other way!
14 15
       def bind[A, B](fa: Parser[A])(f: (A) => Parser[B]): Parser[B] = fa flatMap f
15 16
     }
16 17
   }
@@ -20,7 +21,7 @@ trait Parsers {
20 21
   // The return type is Monad[p.type#Parser]
21 22
   //
22 23
   // This way seems to work without -Ydependent-method-types, yay!
23  
-  def parserMonad[P <: combinator.Parsers](p: P) = new ParsersW[P](p).instance
  24
+  implicit def parserMonad[P <: combinator.Parsers with Singleton] = new ParsersW[P].instance
24 25
 }
25 26
 
26 27
 object Parser extends Parsers
1  example/src/main/scala/scalaz/example/ParserUsage.scala
@@ -14,7 +14,6 @@ object ParserUsage extends App {
14 14
       import scalaz.std.List._ // for Traverse[List]
15 15
       import scalaz.std.util.parsing.combinator.Parser.parserMonad
16 16
 
17  
-      implicit val M: Monad[Parser] = parserMonad(testParser)
18 17
       val sequence: Parser[List[List[String]]] = parsers.sequence
19 18
       parseAll(sequence, s)
20 19
     }

0 notes on commit aa80e47

Please sign in to comment.
Something went wrong with that request. Please try again.