<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="im"><div><br></div><div>
&gt; <span style="font-family:arial,sans-serif;font-size:13px">For some perverse reason I still don&#39;t like do notation.</span></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br>

</span></div></div><div><span style="font-family:arial,sans-serif;font-size:13px">You&#39;re in fine company. Many of the senior folk shun it altogether, especially in a classroom setting. See [1].</span></div><div class="im">
<div>

<span style="font-family:arial,sans-serif;font-size:13px"><br></span></div></div></div></blockquote><div><br></div><div style>Well that&#39;s nice to know. I feel that I can see what&#39;s going on better in the non-do notation, but when I first started C I used to prefer *(p+i) to p[i] quoting the same rationale. That seems silly to me now.</div>
<div style> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="im"><div><span style="font-family:arial,sans-serif;font-size:13px"></span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px">&gt; </span><span style="font-family:arial,sans-serif;font-size:13px">bezis looks far too long as well. Any way to tidy it up?</span></div>

<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div></div><div><font face="arial, sans-serif">The list indices ati and bti are used only once: to retrieve the (first) item matching the predicate. Might Data.List.find be a better fit?</font></div>
</div></blockquote><div><br></div><div style>No, I use them via t1 and t2 to figure out which row to put the squiggle on. The attached picture might put it all in perspective.  </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">

<div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">Replacing findIndex with find should get rid of half of the lets that are just fromIntegral noise.</font></div></div></blockquote><div>
<br></div><div style>Yeah but I still need the row number.</div><div style> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><font face="arial, sans-serif"></font></div>
<div>This sort of falls under the broader rubric of more whitespace is better than less, all other things equal. So consecutive</div><div><br></div><div>&gt; let ... in</div>

<div>&gt; let ... in</div><div><br></div><div>can be merged into a single multiline let, pace C&amp;P diehards.</div></div></blockquote><div><br></div><div style>True.</div><div style><br></div><div style>Thanks,</div><div style>
Adrian.</div><div style><br></div><div style> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>And finally to answer the earlier question: fromSegments returns a PathLike-constrained value. PathLike is subclassed from Monoid.</div>


<div><br></div><div><span style="font-size:13px;font-family:arial,sans-serif">[1] </span><a href="http://www.haskell.org/haskellwiki/Do_notation_considered_harmful" target="_blank">http://www.haskell.org/haskellwiki/Do_notation_considered_harmful</a><span class="HOEnZb"><font color="#888888"><br>


</font></span></div><span class="HOEnZb"><font color="#888888"><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><br></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br>
</span></div></font></span></div><div class="gmail_extra"><span class="HOEnZb"><font color="#888888">

<br clear="all"><div>-- Kim-Ee</div></font></span><div><div class="h5">
<br><br><div class="gmail_quote">On Tue, May 14, 2013 at 9:56 PM, Adrian May <span dir="ltr">&lt;<a href="mailto:adrian.alexander.may@gmail.com" target="_blank">adrian.alexander.may@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 dir="ltr">Thanks everyone. The first suggestion did the trick without needing any other modules. <div><div><br></div><div>&gt; What instance of Monoid is this? </div><div><br></div></div><div>I dunno, but the context is a gantt chart drawing program:</div>



<div><br></div><div><div>data Task = Task {  name :: String,  desc :: String,   dur :: Days  } -- tasks is a list of these and deps is a list of...</div><div>data Dep = Dep {  pre :: String,   post :: String  } -- referring to Task&#39;s name</div>



<div>-- draw the squiggles representing sequential dependencies:</div><div>beziset = foldl atop mempty $ map ((maybe mempty id).bezis) deps</div><div>bezis (Dep bef aft) = </div><div>    findIndex (\t-&gt; name t == bef) tasks &gt;&gt;= \bti -&gt;</div>



<div>    findIndex (\t-&gt; name t == aft) tasks &gt;&gt;= \ati -&gt;</div><div>    let t1 = fromIntegral bti in</div><div>    let d1 = finish (tasks !! bti) in   --finish is begin + duration</div><div>    let t2 = fromIntegral ati in </div>



<div>    let d2 = begin (tasks !! ati) in  --begin is the latest of the end dates of the directly preceding tasks (or project kickoff)</div><div>    return ( -- the following monstrosity is just about my coordinate system</div>



<div>      fromSegments [bezier3 (r2 (1.3,0)) (r2 (d2-d1-1,-(t2-t1)*(1+gap))) (r2 (d2-d1,-(t2-t1)*(1+gap))) ] # </div><div>         translate (r2 (descspace+d1,-t1*(1+gap))) )</div><div><br></div></div><div>beziset then gets `atop`ed onto a Diagram.</div>



<div><br></div><div>bezis looks far too long as well. Any way to tidy it up? (For some perverse reason I still don&#39;t like do notation.) (I know the bezier3 expression is hideous but I can fix that myself.)</div><span><font color="#888888">
<div><br></div><div>Adrian.</div></font></span><div><br></div><div>PS: In my previous job I once spent a week evaluating gantt chart drawing softwares. Now I wrote the one I was looking for in half a day. That&#39;s Haskell!</div>



<div><br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div>On 14 May 2013 20:08, Kim-Ee Yeoh <span dir="ltr">&lt;<a href="mailto:ky3@atamo.com" target="_blank">ky3@atamo.com</a>&gt;</span> wrote:<br>



</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr"><div class="gmail_extra"><div>On Tue, May 14, 2013 at 4:21 PM, Adrian May <span dir="ltr">&lt;<a href="mailto:adrian.alexander.may@gmail.com" target="_blank">adrian.alexander.may@gmail.com</a>&gt;</span> wrote:<br>





<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>I have a really annoying scrap of code:</div>





<div><br></div><div><div>unmaybe Nothing = mempty</div><div>unmaybe (Just dia) = dia</div><div><br></div><div>
It happened because I&#39;m using Diagrams but building my diagram requires looking something up in a list using findIndex, which returns Maybe Int.</div><div></div></div></blockquote></div><br></div>What instance of Monoid is this? Because Int has both a Sum Int and a Product Int instance so you can&#39;t just apply unmaybe to (Just 3 :: Maybe Int).</div>





<div class="gmail_extra"><br></div><div class="gmail_extra">Defining unmaybe Nothing = 0 prompts the question: how will you distinguish misses versus hits on the head of the list? Presumably you don&#39;t want to.</div>

<div class="gmail_extra"><br></div><div class="gmail_extra">You might be interested in the totalized lookup functions defined in my private toolkit (hayoo returns nothing):</div><div class="gmail_extra">

<br></div><div class="gmail_extra"><div class="gmail_extra">-- tlookup :: (Eq a) =&gt; b -&gt; a -&gt; [(a, b)] -&gt; b</div><div class="gmail_extra">tlookup b a abs = fromMaybe b $ lookup a abs</div><div class="gmail_extra">





tlookup0  a abs = tlookup mempty a abs<span><font color="#888888"><br></font></span></div><span><font color="#888888"><div><br></div></font></span></div><span><font color="#888888"><div class="gmail_extra">
<div>-- Kim-Ee</div>
</div></font></span></div>
<br></div></div><div>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></div></blockquote></div><br></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div></div></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div></div>