4 ms·
We (Elixir) would rather define lists on top of non empty lists: list(a) = empty_list() or non_empty_list(a) So you should pass non-empty lists everywhere
by josevalim 2y ago
We (Elixir) would rather define lists on top of non empty lists:
list(a) = empty_list() or non_empty_list(a)
So you should pass non-empty lists everywhere a list is expected. But you can’t pass a list where a non-empty one is expected.
But overall, you are right: our concern is exactly all of the extra function calls that may now suddenly become necessary (and the tension mentioned in the article). We will review our design decisions as we keep on rolling out the type system!
- yawboakye 2y agofor when one expects a list to be non-empty, i think there’s strong argument in favor of an enforcement from the type checker, given that the prove will very likely be necessary. if not in the application code then in the tests.
- greener_grass 2y agoDoes this break down if we want some other types? e.g. list(a) = empty_list() or singleton_list(a) or two_or_more_list(a)