<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
For the record, since I suggested this solution (without actually trying it):<br>
<br>
<font face="monospace">whereIsBM boiList = case boiList of<br>
Nothing -> Nothing<br>
Just (Cons idx lx)<br>
| (idx == Bacon) -> Just 1<br>
| otherwise -> (1 +) <$> (whereIsBM lx)</font><br>
<br>
The problem I did not realize here is that lx is of type BaconOrIndex, not Maybe BaconOrIndex. There are two solutions. What someone suggested of just making whereIsBM receive BaconOrIndex all the way (You're also missing the Empty case, I just realized, which
maybe you confused with Nothing, so I add that one):<br>
<br>
<font face="monospace">whereIsBM boiList = case boiList of</font></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<font face="monospace"> {<br>
</font></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<font face="monospace"> Empty -> Nothing;<br>
Cons idx lx<br>
| (idx == Bacon) -> Just 1<br>
| otherwise -> (1 +) <$> (whereIsBM lx)</font></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<font face="monospace"> }<br>
<br>
</font>The other option is to just wrap lx in Just, but that really feels strange and not what you want, plus you'd still need to account for the Empty case.<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Haskell-Cafe <haskell-cafe-bounces@haskell.org> on behalf of Galaxy Being <borgauf@gmail.com><br>
<b>Sent:</b> 29 March 2021 18:12<br>
<b>To:</b> haskell-cafe <haskell-cafe@haskell.org><br>
<b>Subject:</b> Re: [Haskell-cafe] Maybe won't let me count</font>
<div> </div>
</div>
<div>
<div style="background-color:#fff2e6; border:2px dotted #ff884d"><span style="font-size:12pt; font-family:sans-serif; color:black; font-weight:bold; padding:.2em">This email was sent to you by someone outside the University.</span>
<div style="font-size:10pt; font-family:sans-serif; font-style:normal; padding:.2em">
You should only click on links or attachments if you are certain that the email is genuine and the content is safe.</div>
</div>
<div>
<div dir="ltr">A bit of post-mortem...
<div><br>
</div>
<div>I got this
<div><br>
</div>
<div><font face="monospace">data MyList a = Empty | Cons a (MyList a) deriving (Eq,Ord,Show)</font></div>
<div><font face="monospace">data BaconOrIndex = Bacon | Indx Int deriving (Eq,Ord,Show)<br>
</font>
<div><br>
</div>
<div><font face="monospace">import Data.Maybe<br>
whereIsBM = whereIsBM' 1<br>
whereIsBM' _ Empty = Nothing<br>
whereIsBM' !n (Cons Bacon _) = Just n<br>
whereIsBM' !n (Cons _ lx) = whereIsBM' (succ n) lx<br>
</font></div>
<div><font face="monospace"><br>
</font></div>
<div><font face="monospace">> whereIsBM (Cons (Indx 5) (Cons (Indx 13) (Cons (Indx 2) (Cons (Indx 8) Empty))))</font></div>
<div><font face="monospace">Nothing</font></div>
<div><font face="monospace">> whereIsBM (Cons (Indx 5) (Cons (Indx 13) (Cons Bacon (Cons (Indx 8) Empty))))</font></div>
<div><font face="monospace">Just 3</font><br>
</div>
<div><br>
</div>
<div>to work. Unfortunately, I couldn't get this</div>
<div><br>
</div>
<div><font face="monospace">whereIsBM boiList = go 0<br>
where<br>
go !_ Empty = Nothing<br>
go !acc (Cons idx lx) | (idx == Bacon) = Just acc<br>
| otherwise = go (acc + 1) lx</font><br>
</div>
<div><br>
</div>
<div>to work. Both are nearly identical, but the latter gives this error</div>
<div><br>
</div>
<div><font face="monospace">> whereIsBM (Cons (Indx 5) (Cons (Indx 13) (Cons (Indx 2) (Cons (Indx 8) Empty))))</font></div>
<div><font face="monospace">No instance for (Show (MyList BaconOrIndex -> Maybe Integer))<br>
: arising from a use of `print'<br>
</font></div>
<div><font face="monospace"><br>
</font></div>
<div><font face="arial, sans-serif">This also failed</font></div>
<div><font face="monospace"><br>
</font></div>
<div><font face="monospace">whereIsBM boiList = case boiList of<br>
Nothing -> Nothing<br>
Just (Cons idx lx)<br>
| (idx == Bacon) -> Just 1<br>
| otherwise -> (1 +) <$> (whereIsBM lx)<br>
</font></div>
<div><font face="monospace"><br>
</font></div>
<div><font face="monospace">Couldn't match type `Maybe (MyList BaconOrIndex)'<br>
</font></div>
<div><font face="monospace"> with `MyList BaconOrIndex'<br>
Expected type: MyList BaconOrIndex -> Maybe a<br>
Actual type: Maybe (MyList BaconOrIndex) -> Maybe a</font><br>
</div>
<div><br>
</div>
<div>Not sure why this didn't work. Would like to understand the whole <font face="monospace">
fmap</font> idea as applied here, though.</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
</div>
</div>
</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">On Mon, Mar 29, 2021 at 4:04 AM Henning Thielemann <<a href="mailto:lemming@henning-thielemann.de">lemming@henning-thielemann.de</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<br>
On Mon, 29 Mar 2021, Viktor Dukhovni wrote:<br>
<br>
> Thus I applaud Michael Snoyman's quest to address the absense of a basic <br>
> array type in the `base` library. Perhaps more users would stop abusing <br>
> lists (memoisable iterators) as an indexed store.<br>
<br>
Data.Array actually _was_ part of base-3.<br>
<br>
However, I think we should split 'base' in more smaller parts rather than <br>
making it bigger.<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote>
</div>
</div>
</div>
The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. Is e buidheann carthannais a th’ ann an Oilthigh Dhùn Èideann, clàraichte an Alba, àireamh clàraidh SC005336.
</body>
</html>