I hate it when I make an official release of a program with an ugly snippet of code that I can't figure out how to write more cleanly, only to come up with a solution 10 minutes after pushing the release. I just make the change in the dev branch so it gets incorporated into the next version.
In my defense, the thing I was overlooking was that #Haskell's Maybe
type is an instance of Foldable
. It's not the kind of data type that exactly screams Foldable
, is it?
Side note: I should use Hoogle's search by type signature feature more frequently. I needed a function that looked like this: Monad m => (a -> m ()) -> Maybe a -> m ()
, which is literally just mapM_
.
@me When in doubt, always check to see if `traverse` matches the function you need. It's odd how often `traverse` (or some variant, like `mapM` or `traverse_`) is what you want.
@me That's kinda like forgetting that `for` / `foreach` loops exist. But, ya know, it happens. :)
hlint
is my friend. It tends to remind me of stuff like that.@me I like that hlint + hls can go ahead an apply the transform for you a lot of time.
I do which it provided a code action for ignore (just) this hint for (just) this definition, tho.
@me I don't use emacs, but it works well in Neovim and VS Codium. I've heard it's better in emacs than in vim, but haven't verified that.