[Haskell-cafe] Maybe won't let me count

Andres Loeh mail at andres-loeh.de
Mon Mar 29 17:34:27 UTC 2021


Hi.

In this version

> whereIsBM boiList = go 0
>   where
>     go !_ Empty = Nothing
>     go !acc (Cons idx lx) | (idx == Bacon) = Just acc
>                           | otherwise = go (acc + 1) lx

you abstract from boiList but then don't use it. You should
either remove boiList on the left hand side or add it as a second
argument to the call of the go function.

In this version

> whereIsBM boiList = case boiList of
>                       Nothing -> Nothing
>                       Just (Cons idx lx)
>                         | (idx == Bacon) -> Just 1
>                         | otherwise -> (1 +) <$> (whereIsBM lx)

you are pattern matching on boiList with Nothing / Just, as if
it is of Maybe type, but judging from the other functions and also
the recursive call, you're expecting it to be of type MyList.

Cheers,
Andres


More information about the Haskell-Cafe mailing list