Permalink
Browse files

why doesn't this compile with GHC?

  • Loading branch information...
1 parent 33b1047 commit 636b6412891894577715bd13a45d570b19d95c47 @tianyicui committed Nov 29, 2010
Showing with 23 additions and 1 deletion.
  1. +23 −1 ch08/Parser.hs
View
@@ -1,4 +1,6 @@
-import Prelude hiding (return)
+module Parser where
+
+import Prelude (Char, String)
type Parser a = String -> [(a, String)]
@@ -15,3 +17,23 @@ item = \inp -> case inp of
parse :: Parser a -> String -> [(a, String)]
parse p inp = p inp
+
+(>>=) :: Parser a -> (a -> Parser b) -> Parser b
+p >>= f = \inp -> case parse p inp of
+ [] -> []
+ [(v,out)] -> parse (f v) out
+
+p0 :: Parser (Char, Char)
+p0 =
+ item >>= \x ->
+ item >>= \_ ->
+ item >>= \y ->
+ return (x, y)
+
+-- is equivalent to
+-- p1 :: Parser (Char, Char)
+p1 = do
+ x <- item
+ item
+ y <- item
+ return (x, y)

0 comments on commit 636b641

Please sign in to comment.