<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
First, if you want to use several monads at a time, you should use
monad transformers (see the 'mtl' package). Then you could type your
interpreter function as 'execute :: Command -> StateT ParseState
IO ()'<br>
<br>
Second, ParseState including IO sounds like poor design to me
(basically, in your monad you will end up carrying two pieces of
IO). I can't explain how to do this better, because you haven't
provided the definition of ParseState and execute.<br>
<br>
As for examples, a quick search revealed this extensive answer on
StackOverflow:
<a class="moz-txt-link-freetext" href="https://stackoverflow.com/questions/16970431/implementing-a-language-interpreter-in-haskell#16971570">https://stackoverflow.com/questions/16970431/implementing-a-language-interpreter-in-haskell#16971570</a><br>
<br>
For your particular case, you might want to look at free monads, as
they may offer a cleaner way to implement what you want.
<a class="moz-txt-link-freetext" href="http://www.haskellforall.com/2012/06/you-could-have-invented-free-monads.html">http://www.haskellforall.com/2012/06/you-could-have-invented-free-monads.html</a><br>
<br>
<div class="moz-cite-prefix">On 04/07/2016 10:29 AM, Jake wrote:<br>
</div>
<blockquote
cite="mid:CAAE4QitM5u4zm244759ZUgXxT2T8MCdTKp6a4xvEm-KReqVBLA@mail.gmail.com"
type="cite">
<div dir="ltr">I'm currently in a graphics class where, in order
to provide a standard interface to all of our graphics
libraries, we have to process small scripts that look like this:
<div><br>
</div>
<div>line</div>
<div>0 0 0 1 1 1</div>
<div>circle</div>
<div>0 0 10</div>
<div>scale</div>
<div>0 0 3</div>
<div>save</div>
<div>pic.png</div>
<div><br>
</div>
<div>I successfully wrote a parser with attoparsec that parses
the file into a list of Commands. Now I'm trying to process
that list to produce an IO action, and I thought the State
monad would be useful to keep track of the persistent state of
the shapes to draw and the transformations on them.</div>
<div><br>
</div>
<div>I'm confused about how exactly to do this though. What
should the type of my State be? Right now I have an execute
function that is</div>
<div>execute :: Command -> State ParseState (IO ())</div>
<div>where ParseState is a tuple of stuff. ParseState also
includes an IO () because I wanted to be able to create
multiple pictures one after another, and I couldn't figure out
how to access the previous result value from State to add on
to it in the next one.</div>
<div><br>
</div>
<div>So can anyone offer advice on my specific situation, or
maybe a simpler example of how to go about writing an
interpreter with the State monad?</div>
<div><br>
</div>
<div>Thanks,</div>
<div>Jake</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Haskell-Cafe mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a>
</pre>
</blockquote>
<br>
</body>
</html>