Sounds very interesting … I’ll look forward to future instalments!
Depending on how deep you want to take your analysis, and whether you think it’s the right time to think about these things, there is a language-level issue underlying this question that you might want to think a bit about.
As a language, Elm tends to force package authors to be more specific about types – especially container types like List
or Array
– than they would ideally need to be. As an example, consider something like the view
function in the elm-sortable-table
package, which looks like this:
view : Config data msg -> State -> List data -> Html msg
This quite deliberately works with your own data
type, whatever it is, rather than forcing you to use some secondary type (possibly introducing inconsistencies etc.). However, it does insist on getting a List
(as, for that matter, does the html
package itself).
Now, perhaps it would be better if packages insisted on getting an Array
instead of a List
– that’s quite possible, and I’ll look forward to your analysis. However, the deeper question (if you’re interested, and think it’s the right time to think about it) is whether it would be desirable for Elm to provide a mechanism that allows package authors to avoid insisting on working in one collection type or another.
The intuition behind an interest in this question is something like this. As far as a particular application’s data model is concerned, there will always be reasons to prefer one collection type vs. another. That is, no collection type is optimal for all cases. Of course, it’s always possible to convert from the app’s preferred collection type to whatever a particular package is demanding. However, there are a couple of ways in which this is less than ideal. First, it may be inefficient, especially in cases like view
where it will be done repeatedly. (Though, of course, it may turn out not to matter much in practice). Second, it may discourage developers from selecting the collection type that would actually be ideal for their data, given that working in the “default” type (whatever it is) is easier.
I’m deliberately being vague about what changes would be needed to allow package authors to be less prescriptive about container types, since this is the kind of thing that Elm would want to analyze deeply and innovate. If one were to think about how other languages currently deal with this sort of thing, the minimal thing needed would be support for higher-kinded polymorphism. For instance, if this were a legal function signature in Elm, then elm-sortable-table
and html
wouldn’t have to insist on a List
(or, could at least have variations that don’t insist on a List
).
view : Config collection data msg -> State -> collection data -> Html msg
Now, let me say again that you may have all sorts of good reasons not to be interested in this question, or to think that it’s not a good time to think about it right now. However, if there is going to be a conversation about what Elm’s default collection type should be, I thought it could possibly be a good moment to wonder whether it might be desirable to permit package authors to be less prescriptive about container types.