I was reading an interesting Stack Overflow discussion of the value of higher-kinded types (hereafter HKTs), and noted someone repeatedly commenting, “But when would you use this in a real app?” To put it the way another blog post about HKTs (in Rust), they are “a feature people do not really know what to do with.”
Don’t get me wrong: I’m sympathetic to that desire for concrete examples. I’m interested in these kinds of things not primarily for their intellectual value but for their pragmatic value (though I don’t think those two are as distinct as many people do). I’d also love to see some more real-world examples in those discussions. All too often, the discussions of types in Haskell end up being quite abstract and academic—no surprise, given the language’s origin. But I’m also aware that quite often it’s difficult to see how a given kind of abstraction is useful without jumping into a language which has that abstraction available and using it.
People often get turned off by Haskell (and other similarly high-abstraction languages like Scala) because of challenging terms like monad, applicative, functor, and so on. And again: I get that. To grok Haskell, you need to wrap your head around a lot of math ideas—mainly various properties of sets.
That experience has taught me that my current inability to see the utility of a given abstraction means little about the abstraction. It’s primarily an indicator of my own inexperience.
To the question of the utility HKTs in general—in Haskell, Rust, or somewhere else—I don’t have the knowledge myself (yet) to supply a good answer. Heck, I can’t even explain them very well. (Other people can, though!) But I can say that reading Maybe Haskell showed me clearly that such things can be very useful. Even if I am not yet comfortable using that tool, I see how learning to use it would be profitable in the long-term. And like any good tool, even if you don’t need it every day… when you want it, you really want it.