<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="gmail_quote"><div dir="ltr" class="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="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>