elm-analyse icon indicating copy to clipboard operation
elm-analyse copied to clipboard

Suggest alternative data structures

Open adeschamps opened this issue 8 years ago • 0 comments

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.

  • AllDict lets you use arbitrary types as dictionary keys. If you have type alias PlayerID = Int and type alias Model = { players: Dict PlayerID Player } in your program, then you might be interested in AllDict so that you don't try to look up a player using a value of type alias MonsterID = Int.
  • List.Nonempty gives head and tail functions that don't return Maybes. If you have a function that uses List.head and just passes the Nothing case 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?

adeschamps avatar Jan 06 '18 02:01 adeschamps