elm-analyse
elm-analyse copied to clipboard
Suggest alternative data structures
This is a bit speculative.
I was recently part of a discussion about the various data structures available in third party Elm packages and the situations where one would want to use them. I wonder if it would be possible to automatically detect some of these situations and suggest alternatives.
Two data structures that come to mind are AllDict and List.Nonempty.
AllDictlets you use arbitrary types as dictionary keys. If you havetype alias PlayerID = Intandtype alias Model = { players: Dict PlayerID Player }in your program, then you might be interested inAllDictso that you don't try to look up a player using a value oftype alias MonsterID = Int.List.Nonemptygivesheadandtailfunctions that don't returnMaybes. If you have a function that usesList.headand just passes theNothingcase on to the caller, then a non-empty list might be for you (this is an interesting blog post on the topic).
Both of these suggestions are rather subjective. It's not quite the same as suggesting an alternative Array implementation, because in that case I don't think anyone would disagree with the suggestion. I just really like the idea of elm-analyse as a sort of code review tool in addition to a linter. Is this a direction that elm-analyse might take?