These are chat archives for non/algebra

Nov 2015
Cody Allen
Nov 12 2015 17:10
What’s the reason behind returning Int as opposed to a union type like LT | EQ | GT? 2^32 seems like a lot of possible values when 3 would do the job :). I know it’s what Java does, but does it bring a significant performance advantage? I wouldn’t expect allocations to be an issue, because LT, EQ, and GT would all be singleton objects.
Erik Osheim
Nov 12 2015 17:20
@ceedubs the performance difference is definitely measurable
and checks like c != LT are also a bit slower than c >= 0
i could imagine adding an alternate interface in terms of LT|EQ|GT and letting the instance definer and the caller choose which to use. but it would definitely add some complexity.
(otoh if the instance-definer manually overrides methods like lt and gt anyway, it is less of a problem.)
in the case of spire, we wanted to abstract across what the concrete implementations were already doing, thus we stuck with Int. so far algebra has taken the same approach. if you want to open an issue about changing it we still (barely) have some wiggle room there before MiMA concerns will make changing it really annoying.
Cody Allen
Nov 12 2015 17:23
@non thanks for the explanation
Erik Osheim
Nov 12 2015 17:24
it's a good question, and i hadn't conferred with @avibryant and @johnynek before committing this. it's possible they would prefer a definition more like the one you mention.
Cody Allen
Nov 12 2015 17:26
I definitely have no issue with keeping the Int version around for performance reasons. The ADT version may be nice to have too, but I suppose it also wouldn’t necessarily need to live in algebra. It could be added on as some syntax somewhere else
like most of my questions about algebra, this stems back to the fact that I don’t ever do real math :P
I add a couple numbers together and then make a web service call
not that trying to determine the equality of two Order instances is something you would really do outside of tests
P. Oscar Boykin
Nov 12 2015 18:24
@non another thing about algebra (in theory more than practice) is that we wanted to be a common core for algebird and spire. So far, that hasn't happened, but we made a few accommodations for that, so the fact that spire had an Order and did it that way, I think was part of the deal.