News for hackers. Stuff that matters.
Re:One Way to Represent Things by jan_Inkepa on Thursday February 25, 2021 @10:29PM (#26271101)
I pretty sure the poster meant the general 'fraction' (quotient) construction (set 'a' is like set 'b' but with certain elements to be regarded as the same - 'a rational number is a pair of numbers, where you regard (ax,ay) to be the same as (x,y)'. ), rather than rational numbers exactly. (Similarly, Actionscript 3 had generic lists, but not generic types generally IIRC).
Re:One Way to Represent Things by alanbernstein on Friday February 26, 2021 @07:56AM (#26274293)
I'm not sure what distinction you're making? https://docs.python.org/3/library/fractions.html
Re:One Way to Represent Things by germanier on Friday February 26, 2021 @08:04AM (#26274342)
The same but for non-numbers.
Re:One Way to Represent Things by alanbernstein on Saturday February 27, 2021 @04:10PM (#26288205)
Ah, sure. What use might that have?
Re:One Way to Represent Things by dragonwriter on Thursday February 25, 2021 @11:59PM (#26271508)
Isn't this usually trivial to inplement, but pointless because you'll never want to abstract over it?

It's basically a type characterized by a base type and a canonicalization function that maps all values in that type to a subset of the same type, with those values that have the same canonicalized value being equal.

Re:One Way to Represent Things by jacobolus on Friday February 26, 2021 @03:29AM (#26272555)
In order to deal with quotients it is not necessary to normalize to a single representative for each equivalence class (though sometimes that can be useful).

The more important part is a facility for detecting whether two objects are equivalent, and a guarantee that all other operations respect the structure.

Re:One Way to Represent Things by dragonwriter on Friday February 26, 2021 @10:34AM (#26275771)
> In order to deal with quotients it is not necessary to normalize to a single representative for each equivalence class

I may have been thinking about too close of an analogy with mathematical quotients where there are other operations and you are going to want to apply those to the canonical form generally, but, sure, I can see that.

My point was in languages where you can construct user-defined generics types, a general implementation is usually straightforward but not particularly useful, because it's an abstraction you'd almost never consume except in defining concrete types. General operations on quotient-like types aren't something that there is much call for. And I think that's just as true with or without canonicalization.

I would suspect that that is why, unlike say iterables (or in languages with more powerful type systems, monads) it's not something you see supported out of the box in type systems.