|
|
|
|
|
by kingdomcome50
1781 days ago
|
|
> The requirement[0] from the post is for a non-empty list of file paths I'm sure you could imagine my example record containing more keys no? The requirements from the post are arbitrary and could (should) be anything that best-illustrates the thesis of the post. For example by choosing a representation of their "configuration" that suffers from this silly problem of containing unknown content after parsing, the author introduces the whole `NonEmpty` gymnastics. It's totally avoidable. The irony is that the author was so close to getting it right! > You check the list is non-empty but this information is not available anywhere else in the program The function in my example does statically define that the returned list is non-empty. A "parser" would maybe return the non-empty list if parsing was successful. That's how parsers work. [0] The requirement from the post is, in fact, to only have a single file path. That is the only data actually being used (i.e. required). The other intermediate data structures are a choice of the author. |
|
The post is showing how using more expressive types can simplify your code through a very simple example. You started out saying the NonEmpty type is unnecessary and now you're complaining it's not complicated enough, so it's not clear what your actual objection is here.
> The function in my example does statically define that the returned list is non-empty
The type given in your example was
this is inhabited by (Just []) so no it doesn't statically guarantee that.> A "parser" would maybe return the non-empty list if parsing was successful
That's exactly what the nonEmpty function in the post does: