<div dir="ltr">I've got this <div><br></div><div><font face="monospace">import Data.Maybe<br><br>data MyList a = Empty | Cons a (MyList a) deriving (Eq,Ord,Show)<br>data BaconOrIndex = Bacon | Indx Int deriving (Eq,Ord,Show)<br><br>whereIsBM Empty = Nothing<br>whereIsBM (Cons idx lx) = if (idx == Bacon) then Just 1 else (whereIsBM lx)</font><br></div><div><br></div><div>which I would like to tell me where the <font face="monospace">Bacon</font> is (index), not just if there's <font face="monospace">Bacon,</font> which is what it does now. That is, I need this to happen</div><div><br></div><div>> <font face="monospace">whereIsBM (Cons (Indx 5) (Cons Bacon (Cons (Indx 2) (Cons (Indx 8) Empty))))<br></font></div><div><font face="monospace">Just 2</font></div><div><br></div><div>So I need to traverse a <font face="monospace">BaconOrIndex</font> list and count how deep I went to find the <font face="monospace">Bacon</font> variable. I get the above code to evaluate error-free, but obviously I'm only returning a <font face="monospace">Just 1 </font><font face="arial, sans-serif">when it sees </font><font face="monospace">Bacon</font><font face="arial, sans-serif">. What I need is to have the last part be</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif"> </font><font face="monospace">. . . else (1 + whereIsBM lx)</font></div><div><br></div><div> work; but it keeps giving the error<br></div><div><br></div><div><font face="monospace">Non type-variable argument in the constraint: Num (Maybe a)<br>      (Use FlexibleContexts to permit this)<br>    • When checking the inferred type<br>        whereIsBM :: forall a.<br>                     (Num a, Num (Maybe a)) =><br>                     MyList BaconOrIndex -> Maybe a</font><br></div><div><br></div><div>I haven't a clue what this means. Eventually, I'll wrap this in something that handles the <font face="monospace">Nothing</font> and  does <font face="monospace">fromJust </font>on the alternative. This whole effort is because if I didn't use the <font face="monospace">Maybe</font> strategy, and said </div><div><br></div><div><font face="monospace">whereIsBM Empty = 0</font></div><div><font face="monospace">...</font></div><div><br></div><div>it would never give back <font face="monospace">0</font> if it didn't find <font face="monospace">Bacon</font>, rather, it would simply return the whole countdown to <font face="monospace">Empty</font>. What can I do to make <font face="monospace">Maybe </font>work here?<br></div><div><br></div><div>LB</div></div>