Sorry to bother again. I just cannot figure out how it could compile.
I got compile errors.
Can someone point out what is right code to use a do notion to make a
Parser works.

Thanks in advance.
--------------------------------------------------------------------------------------------
newtype Parser a = P { parse :: (String -> [(a,String)]) }

instance Monad Parser where
   return v = P (\s -> [(v,s)])
   p >>= f = P (\s -> case parse p s of
                       []    -> []
                       [(v,str)] -> parse (f v) str)
   fail _ = P (\_ -> [])


item :: Parser Char
item = \inp -> case inp of
                    [] -> []
                    (x:xs) -> [(x,xs)]

p :: Parser (Char,Char)
p = do x <- item
       item
       y <- item
       return (x,y)
---------------------------------------------------------------------------------
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to