Open morteako opened 4 months ago
Nice. So basically we can only apply these if the set/dict is constructed right there (fromList
, insert
, singleton
) and is non-empty.
(And I think you mean List.member c (Dict.toList Dict.empty)
instead of List.member c (Dict.member Dict.empty)
in the "not reported" example)
Ah, yes. That seems (unfortunately) correct.
Those restrictions seems to make this rule pretty niche, so I don't think it is worth to implement it probably. I think it would be a good rule in the general case, but having the possibility to create type errors is of course really bad.
Sounds like a good idea :+1: Thank you both for your input :relaxed:
I wonder if there are other conversations (for instance List.isEmpty (Dict.toList dict)
) that could be done with the base type's functions, and that we don't already support.
@jfmengels
I think these are not supported.
Dict.fromList (List.singleton (k,v)) ---> Dict.singleton k v
List.length (Set.toList set) ---> Set.size set
-- also for Dict.keys and Dict.values List.length (Dict.toList dict) ---> Dict.size dict
-- also for Dict.keys and Dict.values List.isEmpty (Dict.toList dict) ---> Dict.isEmpty dict
List.isEmpty (Set.toList set) ---> Set.isEmpty set
List.member k (Dict.keys dict) ---> Dict.member k dict
List.member k (Set.toList set) ---> Set.member k set
What the rule should do: Replace List.member on Set.toList/Dict.keys with Set/Dict.member
What problems does it solve: Simplifying and optimizes unnecessary convertions
Example of things the rule would report:
Example of things the rule would not report: Since Set/Dict.member requires comparable, but List.member does not, applying this replacement to Set/Dict.empty, could lead to a type error. So therefore we should/could not replace it in that case. (But it should be caught by some other simplification rule)
The above should be simplified to
False
anyways, by the callOnEmptyReturnsCheckShould this be part of the Simplify rule or should it be a new rule?
Part of Simplify
I am looking for: