<div><span class="gmail_quote">On 11/21/07, <b class="gmail_sendername">apfelmus</b> <<a href="mailto:firstname.lastname@example.org">email@example.com</a>> 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
<div>That'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>In fact, it seems like I can implement the original "list" and "state" examples from the Unimo paper in terms of Prompt as well, using a specialized observation function. For example:</div>
<div><font face="courier new,monospace">data StateP s a where<br> Get :: StateP s s<br> Put :: s -> StateP s ()</font></div>
<p><font face="courier new,monospace">runStateP :: Prompt (StateP s) a -> s -> (a,s)<br>runStateP (PromptDone a) s = (a,s)<br>runStateP (Prompt Get k) s = runStateP (k s) s<br>runStateP (Prompt (Put s) k) _ = runStateP (k ()) s
<p><font face="courier new,monospace">instance MonadState s (Prompt (StatePrompt s)) where<br> get = prompt Get<br> put = prompt . Put</font></p>
<p>Strangely, this makes me less happy about Prompt rather than more; if it's capable of representing any reasonable computation, it means it's not really the "targeted silver bullet" I was hoping for. On the other hand, it still seems useful for what I am doing.
<p>I definitely feel like the full term implementation (like the Unimo paper describes) is overkill; unless I'm misunderstanding what's going on there, you're basically destroying any ability for the compiler to reason about your computations by reifying them into data. As long as (>>=) and return are functions that get inlined, lots of extraneous computation can be eliminated as the compiler "discovers" the monad laws through compile-time beta-reduction; once you turn them into data constructors that ability basically goes away.
<div>That said, the generalization to monad transformers and the metaprogramming techniques demonstrated look pretty cool.</div>
<p><font face=""> -- ryan</font></p></div></div>