On 19 March 2010 04:35, 国平张 zhangguop...@gmail.com wrote:
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.
It looks like the p parser may have the wrong indentation -
Sorry. The same error, This is new stuff.
---
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
2010/3/19 国平张 zhangguop...@gmail.com:
Sorry. The same error, This is new stuff.
Ah indeed - I didn't spot that one as I only read the code rather than ran it.
With the change the parser type to use /newtype/ all the primitive
parsers have to be encoded inside the newtype's constructor
Sorry :-). I am using Hugs, anything I did wrong ?
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
国平张 wrote:
Sorry :-). I am using Hugs, anything I did wrong ?
item :: Parser Char
item = Parser (\inp - case inp of
^^^ the second Parser should be a P, which is a data constructor.
Cheers,
Hi
I'm sorry about that, I should have check the last message runs, but I
typed it from a computer that I don't develop on. The code below
should run as I've tested it this time.
newtype Parser a = P { parse :: (String - [(a,String)]) }
instance Monad Parser where
return v = P (\s -
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
Thanks very much. It works!
I just wonder if you can help me to define a Monad to make do notion
works :-) ?
I know it is bothering, but I just ever tried to define a Monad,
failed either. What I did to define a Monad was:
instance Monad Parser where
return v = (\inp-[(v,inp)])
f = g = =
Am Mittwoch 17 März 2010 16:35:08 schrieb 国平张:
Thanks very much. It works!
I just wonder if you can help me to define a Monad to make do notion
works :-) ?
To make an instance of Monad, you must create a new datatype, for example
module Parse where
newtype Parser a = P { parse :: (String -
Hi,
I am a beginner for haskell. I was stuck with a sample of programming
in haskell. Following is my code:
-
import Prelude hiding (return, fail)
type Parser a = (String-[(a,String)])
return :: a - Parser a
return v =
Hi,
You can only use do notation if you actually create an instance of Monad,
which for Parser you haven't done. To continue as is, replace the first line
with:
import Prelude hiding (return, fail, (=))
and the p function with
p = item = \x - item = \_ - item = \y - return (x, y)
I've
11 matches
Mail list logo