Open roetlich opened 4 years ago
I tried solving this with #12, but I don't know if that's the right solution. @averynortonsmith do you have feedback?
Good catch! I'm not sure how intersection
and difference
ended up broken, but you're right that adding a call to toList
in the loop should solve it. Thanks for the clear issue write-up!
You bring up the possibility of expanding map
(and possibly other functions like filter
, reduce
, etc) to work with sets and other structures. This is something I've gone back-and-forth on: on the one hand, reducing the number of types that a function like map
accepts helps give the language a more "strongly-typed" feel and makes code more explicit. On the other hand it may be more convenient to have map
work on more types without a conversion.
In the end I think the answer lies in the principle of least astonishment. If users of Pointless expect structures like sets to be map-able, then they probably should be. Here's another question though: should mapping a function over a set return a list (as your new implementation in #12 does), or should it first convert the list back to a set? I'd like to pull the changes you've made, but I'd be curious to see what you think about this question first.
Well, in most functional languages I used, there is module system. That makes it easy to differentiate List.map and Set.map etc. But such an verbose style maybe doesn't fit pointless. You know, to many "points". :)
I agree, I always imagine map to return the collection type that I put in.
But in this case, the for
comprehension is clearly meant to always return a list. Maybe the solution is to make a new function, mapToList
or something like that, that can be used by for
?
In prelude/set.ptls both
difference
andintersection
use afor
comprehension on a set. Sadly, when I tried to use them, they crash :(It can easily be "fixed" by calling toList on the set:
I could make a PR with that change, but it looks less nice, and I'm assuming this is a regression (i.e.
for
on a Set worked at some point). A proper fix would be making for comprehensions on sets work.If you point me to the right file(s) I could check if can fix this myself.
This is the error message I get: