Re: [Haskell-cafe] Very simple parser

2007-07-04 Thread Alexis Hazell
On Tuesday 03 July 2007 09:51, Arie Peterson wrote: No, there is a 'State s' monad provided (for arbitrary state type 's'), which implements the 'get' and 'put' methods. In other words, 'State s' is an instance of the 'MonadState s' class. This terminology can be really confusing at first.

Re: [Haskell-cafe] Very simple parser

2007-07-04 Thread Arie Peterson
Alexis Hazell wrote: | This may be a stupid question, but i don't understand how (indeed, if) one | can | maintain multiple states using the State monad, since 'get' etc. don't | seem | to require that one specify which particular copy of a State monad one | wishes | to 'get' from, 'put' to etc.?

Re: [Haskell-cafe] Very simple parser

2007-07-04 Thread Ilya Tsindlekht
On Thu, Jul 05, 2007 at 12:58:06AM +1000, Alexis Hazell wrote: On Tuesday 03 July 2007 09:51, Arie Peterson wrote: No, there is a 'State s' monad provided (for arbitrary state type 's'), which implements the 'get' and 'put' methods. In other words, 'State s' is an instance of the

[Haskell-cafe] Very simple parser

2007-07-02 Thread Gregory Propf
As a programming exercise I'm trying to use the State monad to create a simple parser. It's for a very simple assembly language for a simple virtual machine. The state is a string of instructions. I want to be able to call something like getNextInstruction to pull out the next instruction

Re: [Haskell-cafe] Very simple parser

2007-07-02 Thread Arie Peterson
Gregory Propf wrote: As a programming exercise I'm trying to use the State monad to create a simple parser. It's for a very simple assembly language for a simple virtual machine. The state is a string of instructions. I want to be able to call something like getNextInstruction to pull out

Re: [Haskell-cafe] Very simple parser

2007-07-02 Thread Stefan O'Rear
vim: set ft=lhaskell: On Mon, Jul 02, 2007 at 02:25:57PM -0700, Gregory Propf wrote: | As a programming exercise I'm trying to use the State monad to create | a simple parser. It's for a very simple assembly language for a | simple virtual machine. The state is a string of instructions. I |

Re: [Haskell-cafe] Very simple parser

2007-07-02 Thread Gregory Propf
of the examples seem to just use functions that manipulate a state but do not create a new datatype. - Original Message From: Arie Peterson [EMAIL PROTECTED] To: haskell-cafe@haskell.org Sent: Monday, July 2, 2007 2:46:14 PM Subject: Re: [Haskell-cafe] Very simple parser Did you look

Re: [Haskell-cafe] Very simple parser

2007-07-02 Thread Hugh Perkins
Graham Hutton has some great tutorials on parsing. Check out the Are parsers monodic? thread (not exact name) for a good reference. There's also a good tutorial at http://www.cs.nott.ac.uk/~gmh/book.html In Section Slides, click on 8 Functional parsers, but you may just want to start from 1.

Re: [Haskell-cafe] Very simple parser

2007-07-02 Thread Arie Peterson
Gregory Propf wrote: | [...] For example, am I to assume that I need to | create my own instance of State and then define get and put for it? No, there is a 'State s' monad provided (for arbitrary state type 's'), which implements the 'get' and 'put' methods. In other words, 'State s' is an

Re: [Haskell-cafe] Very simple parser

2007-07-02 Thread Gregory Propf
Message From: Arie Peterson [EMAIL PROTECTED] To: haskell-cafe@haskell.org Sent: Monday, July 2, 2007 4:51:59 PM Subject: Re: [Haskell-cafe] Very simple parser To get you going, start with the example from the documentation, modified slightly: tick :: State Int String tick = do n - get

Re: [Haskell-cafe] Very simple parser

2007-07-02 Thread Tim Chevalier
On 7/2/07, Gregory Propf [EMAIL PROTECTED] wrote: This was a bit baffling too. It appears that there's an implied argument to runTick. This also works and makes it more explicit. I suppose the compiler just works out that the only place to put the 'n' is after tick. runTick :: Int -

Re: [Haskell-cafe] Very simple parser

2007-07-02 Thread Gregory Propf
Chevalier [EMAIL PROTECTED] To: Gregory Propf [EMAIL PROTECTED] Cc: haskell-cafe@haskell.org Sent: Monday, July 2, 2007 5:37:41 PM Subject: Re: [Haskell-cafe] Very simple parser On 7/2/07, Gregory Propf [EMAIL PROTECTED] wrote: This was a bit baffling too. It appears that there's an implied