<br>
<div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Message: 2<br>
From: &quot;David House&quot; &lt;<a href="mailto:dmhouse@gmail.com">dmhouse@gmail.com</a>&gt;<br>Subject: [Haskell-cafe] Writing an extensible interpreter</blockquote><div>&nbsp;</div>&nbsp;<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I'm in the process of writing an interpreter for the self-modifying<br>automaton languages SMATINY [1], designed by ihope (whose name some of<br>you may recognise from IRC). The current effort is online [2], but<br>it's at a rather early stage and there's a few modifications I'd like
<br>to make to it.</blockquote><div><br>
[snip] <br>
</div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">However, the remaining issue is step 1): how would the metacode handle<br>additional constructors to the Step ADT? Type classes won't work here:
<br>the intepreter has a type of [Step] -&gt; String. With type classes this<br>would have a type of something like Step a =&gt; [a] -&gt; String, but by<br>the homogeneity of lists you'd only be able to have one type of step
<br>in your program.<br><br>
</blockquote></div>You can get around the homogeneity of lists problem with existential types:<br>
<br>
<a href="http://www.haskell.org/hawiki/ExistentialTypes">http://www.haskell.org/hawiki/ExistentialTypes</a><br>
<a href="http://halogen.note.amherst.edu/~jdtang/scheme_in_48/tutorial/evaluator2.html#equal">http://halogen.note.amherst.edu/~jdtang/scheme_in_48/tutorial/evaluator2.html#equal</a><br>
<br>
Another solution might be to eliminate the algebraic data type entirely
and have the Parsec actions return a Smatiny action.&nbsp; Instead of
dispatching on the constructor of Step, package up any information you
need as a closure and make Step a type synonym for 'Smatiny ()' or
'Smatiny a' or whatever type you need.&nbsp; Then the interpreter main
loop just executes the action returned by the parser.&nbsp; <br>
<br>
- Jonathan<br>