3 ms·
They still work on plain lists with the same syntax you could always use (that is, lists are a member of the Foldable type class), right? If so, then this prim
by geofft 7y ago
They still work on plain lists with the same syntax you could always use (that is, lists are a member of the Foldable type class), right?
If so, then this primarily seems like an issue of how to present the documentation and not the mechanics of the change itself. Instead of autogenerating docs that say concat :: Foldable t => t (t a) -> t a (or whatever) and making people think about Foldable, write docs that say that concat is still [[a]] -> [a], with a note at the bottom saying, by the way, this generalization exists, click here to see the more complicated version if you've decided you care about Foldable. Probably the text of the docs remains the same, in fact ("concatenate a list of lists together into a single list"), you just display the real prototype and explain that "list" could also mean something else. (There's a number of ways to implement this, from writing docs by hand, to extending the doc protocol to support this specific case of lists and Foldable, to extending the doc protocol to support documenting a fake function prototype and then have a link to the real function at the bottom, and using the type system to ensure that the fake prototype is just a special case of the real function.)
A corollary is that documentation presentation is an inseparable part of library / tool design.
- kqr 7y agoThe other problem are type errors, which would then require knowing about Foldable to operate on lists. The same type of solution that you propose for docs can work here too, though. The compiler can trivially substitute the typeclass for any known instance.