Re: [Haskell-cafe] stuck with a sample of programming in haskell

2010-03-19 Thread Stephen Tetley
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 -

Re: [Haskell-cafe] stuck with a sample of programming in haskell

2010-03-19 Thread 国平张
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

Re: [Haskell-cafe] stuck with a sample of programming in haskell

2010-03-19 Thread Stephen Tetley
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

Re: [Haskell-cafe] stuck with a sample of programming in haskell

2010-03-19 Thread 国平张
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

Re: [Haskell-cafe] stuck with a sample of programming in haskell

2010-03-19 Thread Jochem Berndsen
国平张 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,

Re: [Haskell-cafe] stuck with a sample of programming in haskell

2010-03-19 Thread Stephen Tetley
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 -

Re: [Haskell-cafe] stuck with a sample of programming in haskell

2010-03-18 Thread 国平张
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

Re: [Haskell-cafe] stuck with a sample of programming in haskell

2010-03-17 Thread 国平张
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 = =

Re: [Haskell-cafe] stuck with a sample of programming in haskell

2010-03-17 Thread Daniel Fischer
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 -

[Haskell-cafe] stuck with a sample of programming in haskell

2010-03-16 Thread 国平张
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 =

Re: [Haskell-cafe] stuck with a sample of programming in haskell

2010-03-16 Thread Michael Snoyman
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