<div dir="ltr"><div class="gmail_extra">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>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" style>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" style><br></div><div class="gmail_extra" style>You might be interested in the totalized lookup functions defined in my private toolkit (hayoo returns nothing):</div><div class="gmail_extra" style>

<br></div><div class="gmail_extra" style><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<br></div><div><br></div></div><div class="gmail_extra"><div>-- Kim-Ee</div>
</div></div>