Skip to main content


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_.

in reply to Jonathan Lamothe

Hah. In a similar situation, I knew I wanted whenJust (which is provided by various libraries on hackage), but in the end, I realized I could just use for_ from base. It's amazing how many functions are just traverse (or traverse_).
in reply to Roufnichan LeGauf 🌈

@Kalamata Hari Yeah, any time I end up writing a case statement on a Maybe or Either and one of the branches is -> return (), I die a little inside, because I know there's probably a better way that I'm just not seeing.
in reply to Jonathan Lamothe

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.
in reply to Jonathan Lamothe

That's kinda like forgetting that `for` / `foreach` loops exist. But, ya know, it happens. 😀
in reply to Jonathan Lamothe

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.

in reply to Jonathan Lamothe

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.

This website uses cookies. If you continue browsing this website, you agree to the usage of cookies.