<div dir="ltr">Thanks everyone. The first suggestion did the trick without needing any other modules. <div><br></div><div>&gt; What instance of Monoid is this? </div><div><br></div><div style>I dunno, but the context is a gantt chart drawing program:</div>
<div style><br></div><div style><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 style>-- 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 style>beziset then gets `atop`ed onto a Diagram.</div>
<div style><br></div><div style>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>
<div style><br></div><div style>Adrian.</div><div style><br></div><div style>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 style><br></div><div style><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">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>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="im">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 class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888"><div><br></div></font></span></div><span class="HOEnZb"><font color="#888888"><div class="gmail_extra">
<div>-- Kim-Ee</div>
</div></font></span></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>