<div><span class="gmail_quote">On 11/21/07, <b class="gmail_sendername">apfelmus</b> &lt;<a href="mailto:apfelmus@quantentunnel.de">apfelmus@quantentunnel.de</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">A slightly different point of view is that you use a term implementation<br>for your monad, at least for the interesting primitive effects
</blockquote>
<div>&nbsp;</div>
<div>That&#39;s a really interesting point of view, which had struck me slightly, but putting it quite clearly like that definitely helps me understand what is going on.</div>
<div>&nbsp;</div>
<div>In fact, it seems like I can implement the original &quot;list&quot; and &quot;state&quot; examples from the Unimo paper in terms of Prompt as well, using a specialized&nbsp;observation function.&nbsp; For example:</div>
<div>&nbsp;</div>
<div>
<div><font face="courier new,monospace">data StateP s a where<br>&nbsp;&nbsp; Get :: StateP s s<br>&nbsp;&nbsp; Put :: s -&gt; StateP s ()</font></div>
<div>
<p><font face="courier new,monospace">runStateP :: Prompt (StateP s) a -&gt; s -&gt; (a,s)<br>runStateP (PromptDone a)&nbsp;&nbsp;&nbsp;&nbsp; s = (a,s)<br>runStateP (Prompt Get k)&nbsp;&nbsp;&nbsp;&nbsp; s = runStateP (k s) s<br>runStateP (Prompt (Put s) k) _ = runStateP (k ()) s
</font></p>
<p><font face="courier new,monospace">instance MonadState s (Prompt (StatePrompt s)) where<br>&nbsp;&nbsp; get = prompt Get<br>&nbsp;&nbsp; put = prompt . Put</font></p>
<p>Strangely, this makes me less happy about Prompt rather than more; if it&#39;s capable of representing any reasonable computation, it means it&#39;s not really the &quot;targeted silver bullet&quot; I was hoping for.&nbsp; On the other hand, it still seems useful for what I am doing.
</p>
<p>I definitely feel like the full term implementation (like the Unimo paper describes) is overkill; unless I&#39;m misunderstanding what&#39;s going on there, you&#39;re basically destroying any ability for the compiler to reason about your computations by reifying them into data.&nbsp; As long as (&gt;&gt;=) and return are functions that get inlined, lots of extraneous computation can be eliminated as the compiler &quot;discovers&quot; the monad laws through compile-time beta-reduction; once you turn them into data constructors that ability basically goes away.
</p></div></div>
<div>That said, the generalization to monad transformers and the metaprogramming techniques demonstrated look pretty cool.</div>
<div>
<p><font face="">&nbsp;&nbsp; -- ryan</font></p></div></div>