<div dir="ltr"><br><br><div class="gmail_quote">On Fri, Apr 8, 2011 at 2:47 AM, Mark Bradley <span dir="ltr">&lt;<a href="mailto:barkmadley@gmail.com">barkmadley@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">On Thu, Apr 7, 2011 at 11:22 PM, Michael Snoyman &lt;<a href="mailto:michael@snoyman.com">michael@snoyman.com</a>&gt; wrote:<br>
&gt; A few points:<br>
&gt; 1) The cost is twofold: making Hamlet more complex from a user perspective,<br>
&gt; and making the codebase more complex. I&#39;m not a fan of either, unless it&#39;s<br>
&gt; really justified.<br>
&gt; 2) I&#39;m not really certain how your example below works as far as<br>
&gt; disambiguating Maybe versus [] (i.e., $maybe versus $forall), but if we&#39;re<br>
&gt; willing to go in this direction, you already have $let for free:<br>
&gt; $forall foo &lt;- foos<br>
&gt;     $forall foobar &lt;- return $ bar foo<br>
&gt;         #{foobar}<br>
<br>
</div>I was really going out there with my suggestions and examples.  The<br>
real benefit of a unified approach is that you can extend it to apply<br>
to your custom container types.  Making it pretty similar to foldable<br>
but with an default behaviour when the data structure is empty.<br>
<br></blockquote><div>Actually, forgetting the rest of the discussion here, I think extending $forall to work on any Foldable is a great idea. Any objections?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">


Also if you already have let for free using forall and return, why not<br>
make a sugared version that compiles down to that?<br>
<div><div></div><div class="h5"><br></div></div></blockquote><div>I haven&#39;t looked at your patch yet (thank you btw), but my concern is that introducing $let, the same way it&#39;s used in Haskell, introduces scoping issues that we don&#39;t otherwise have. $forall and $maybe already add a significant complexity to deal with the bound variable names, but at least it&#39;s bound for only the inner block. With $let, we would want it to be bound for the remainder of the block most likely. So we&#39;d have two choices:</div>

<div><br></div><div>* Implement a whole bunch of complexity defining and implementing new scoping rules.</div><div>* Have totally different semantics from Haskell.</div><div><br></div><div>I&#39;m not sure which approach your patch took. But maybe the problem was with my choice of name ($let); $with would likely make more sense for the inner block approach. But even so, I&#39;m still concerned that this is complexity without enough reward.</div>

<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div class="h5">
&gt; Here, return would be for the [] instance of Monad. We could also use<br>
&gt; $maybe, using the Maybe instance of Monad.<br>
&gt; Michael<br>
&gt;<br>
&gt; On Thu, Apr 7, 2011 at 3:46 PM, Mark Bradley &lt;<a href="mailto:barkmadley@gmail.com">barkmadley@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; On Thu, Apr 7, 2011 at 10:34 PM, Mark Bradley &lt;<a href="mailto:barkmadley@gmail.com">barkmadley@gmail.com</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt; &gt; On Thu, Apr 7, 2011 at 7:51 PM, Max Cantor &lt;<a href="mailto:mxcantor@gmail.com">mxcantor@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt;&gt; put me in the opposed category.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; You can just as easily put:<br>
&gt;&gt; &gt;&gt;  let formId rs = fromMaybe &quot;&quot; $ lookup $...<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; in the haskell function that loads the hamlet file then you just have<br>
&gt;&gt; &gt;&gt; to put<br>
&gt;&gt; &gt;&gt;  #{formId rs}<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; in the hamlet.  I think adding syntax should be done only when very<br>
&gt;&gt; &gt;&gt; necessary.  seems like a very small win here at a big cost.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Where is the cost? Most of the effort would be just glueing together<br>
&gt;&gt; &gt; some pieces of existing code. Given that there are already two places<br>
&gt;&gt; &gt; where hamlet does variable binding, adding a third will not hurt it,<br>
&gt;&gt; &gt; or perhaps a single more expressive form of variable binding is<br>
&gt;&gt; &gt; required. Something like monadic bind (&gt;&gt;=) where you can bind<br>
&gt;&gt; &gt; non-monadic values using the identity monad.<br>
&gt;&gt;<br>
&gt;&gt; An example:<br>
&gt;&gt;<br>
&gt;&gt; $bind row &lt;- rs<br>
&gt;&gt;    $bind formId &lt;- Identity $ fromMaybe &quot;&quot; $ IntMap.lookup $ getInt<br>
&gt;&gt; &quot;form_id&quot; row<br>
&gt;&gt;        &lt;td&gt;#{formId counties}<br>
&gt;&gt;        &lt;td&gt;#{formId customers}<br>
&gt;&gt;<br>
&gt;&gt; It could also be possible to do else cases where it didn&#39;t bind:<br>
&gt;&gt;<br>
&gt;&gt; -- list bind<br>
&gt;&gt; $bind row &lt;- rs<br>
&gt;&gt;    -- identity bind<br>
&gt;&gt;    $bind formId &lt;- Identity $ fromMaybe &quot;&quot; $ IntMap.lookup $ getInt<br>
&gt;&gt; &quot;form_id&quot; row<br>
&gt;&gt;        &lt;td&gt;#{formId counties}<br>
&gt;&gt;        &lt;td&gt;#{formId customers}<br>
&gt;&gt;        -- maybe bind<br>
&gt;&gt;        $bind someValue &lt;- someMaybeValue<br>
&gt;&gt;            &lt;div&gt;content<br>
&gt;&gt;        -- maybe value was Nothing<br>
&gt;&gt;        $nobind<br>
&gt;&gt;            &lt;div&gt;other content<br>
&gt;&gt;    -- not possible with identity bind possible place for error/warning<br>
&gt;&gt;    $nobind<br>
&gt;&gt;        &lt;div&gt;This should not happen!<br>
&gt;&gt;<br>
&gt;&gt; -- empty list<br>
&gt;&gt; $nobind<br>
&gt;&gt;    &lt;div&gt;i left my content in my other pants<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; yes, if you have a situation where many handlers are calling the same<br>
&gt;&gt; &gt;&gt; hamlet file, there might be some duplication, but then you can always raise<br>
&gt;&gt; &gt;&gt; the formId function to a top-level function.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; max<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;  On Apr 7, 2011, at 5:15 PM, Michael Snoyman wrote:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; I&#39;ve been very hesitant about adding more features to Hamlet,<br>
&gt;&gt; &gt;&gt;&gt; especially ones that are already implemented in Haskell. That&#39;s been my<br>
&gt;&gt; &gt;&gt;&gt; reasoning for avoiding any kind of variable definitions until now. However,<br>
&gt;&gt; &gt;&gt;&gt; this does seem like a compelling use case.<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; I don&#39;t think it would make sense to limit it to foralls: it makes as<br>
&gt;&gt; &gt;&gt;&gt; much sense in maybes, and I think it would be confusing if it only applied<br>
&gt;&gt; &gt;&gt;&gt; in some cases. As for syntax, how about:<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; $forall row &lt;- rs<br>
&gt;&gt; &gt;&gt;&gt;     $let formId = fromMaybe &quot;&quot; $ IntMap.lookup $ getInt &quot;form_id&quot; row<br>
&gt;&gt; &gt;&gt;&gt;     ...<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; I&#39;m not 100% sold on this yet, what does everyone else think?<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; One last note: I&#39;m probably going to be announcing a feature freeze on<br>
&gt;&gt; &gt;&gt;&gt; Yesod 0.8 *very* soon, and making a beta release to Yackage so that people<br>
&gt;&gt; &gt;&gt;&gt; can test. If you have any last-minute input, now&#39;s the time. I&#39;m planning on<br>
&gt;&gt; &gt;&gt;&gt; giving the beta test period about a week, and then releasing to Hackage.<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; Michael<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; On Thu, Apr 7, 2011 at 2:57 AM, &lt;<a href="mailto:vagif.verdi@gmail.com">vagif.verdi@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt;&gt;&gt; I noticed a pattern that in hamlet $forall i often retrieve the same<br>
&gt;&gt; &gt;&gt;&gt; value<br>
&gt;&gt; &gt;&gt;&gt; from a map, Sometimes 3,4 times.<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt;    $forall row &lt;- rs<br>
&gt;&gt; &gt;&gt;&gt;            &lt;td&gt;&lt;a href=@{FormR (getInt &quot;form_id&quot; row)}&gt;#{getStr<br>
&gt;&gt; &gt;&gt;&gt; &quot;form_name&quot;<br>
&gt;&gt; &gt;&gt;&gt; row}<br>
&gt;&gt; &gt;&gt;&gt;            &lt;td&gt;#{getStr &quot;docname&quot; row}<br>
&gt;&gt; &gt;&gt;&gt;            ...<br>
&gt;&gt; &gt;&gt;&gt;            &lt;td&gt;#{fromMaybe &quot;&quot; (IntMap.lookup (getInt &quot;form_id&quot; row)<br>
&gt;&gt; &gt;&gt;&gt; counties)}<br>
&gt;&gt; &gt;&gt;&gt;            &lt;td&gt;#{fromMaybe &quot;&quot; (IntMap.lookup (getInt &quot;form_id&quot; row)<br>
&gt;&gt; &gt;&gt;&gt; customers)}<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; Would it be possible to allow let statement in forall for often used<br>
&gt;&gt; &gt;&gt;&gt; values ?<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; Regards,<br>
&gt;&gt; &gt;&gt;&gt; Vagif Verdi<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; _______________________________________________<br>
&gt;&gt; &gt;&gt;&gt; web-devel mailing list<br>
&gt;&gt; &gt;&gt;&gt; <a href="mailto:web-devel@haskell.org">web-devel@haskell.org</a><br>
&gt;&gt; &gt;&gt;&gt; <a href="http://www.haskell.org/mailman/listinfo/web-devel" target="_blank">http://www.haskell.org/mailman/listinfo/web-devel</a><br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; _______________________________________________<br>
&gt;&gt; &gt;&gt;&gt; web-devel mailing list<br>
&gt;&gt; &gt;&gt;&gt; <a href="mailto:web-devel@haskell.org">web-devel@haskell.org</a><br>
&gt;&gt; &gt;&gt;&gt; <a href="http://www.haskell.org/mailman/listinfo/web-devel" target="_blank">http://www.haskell.org/mailman/listinfo/web-devel</a><br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; web-devel mailing list<br>
&gt;&gt; &gt;&gt; <a href="mailto:web-devel@haskell.org">web-devel@haskell.org</a><br>
&gt;&gt; &gt;&gt; <a href="http://www.haskell.org/mailman/listinfo/web-devel" target="_blank">http://www.haskell.org/mailman/listinfo/web-devel</a><br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; --<br>
&gt;&gt; &gt; -barkmadley<br>
&gt;&gt; &gt; sent from an internet enabled device<br>
&gt;&gt; &gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; -barkmadley<br>
&gt;&gt; sent from an internet enabled device<br>
&gt;<br>
&gt;<br>
<br>
<br>
<br>
</div></div>--<br>
<div><div></div><div class="h5">-barkmadley<br>
sent from an internet enabled device<br>
</div></div></blockquote></div><br></div>