-
Notifications
You must be signed in to change notification settings - Fork 10
Add Ord instance for CList #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Obviously there's not a canonical ordering on CLists, but this is one of the two obvious ones I can see. I think it's useful to have some ordering defined: if people need another one for some reason, it can be implemented separately. |
|
I'm not sure it is appropriate at all. Where order is important to users On Monday, August 22, 2016, Xitian9 notifications@github.com wrote:
|
|
I'm using a modified version of the planar-graph module, which uses clists for node edges. In my case, the planar graphs furthermore have coloured nodes, and can be coloured by planar graphs. The result is a tree of planar graphs. In order to compare whether two such graphs are isomorphic, their nodes need to be ordered so that nodes of the same colour class are adjacent. I've implemented this using groupWith, which requires an ordering on node colours. Since nodes can be coloured by planar graphs, this requires an ordering of planar graphs, which in turn requires an ordering of the clists representing their edges. I'm willing to believe that this need is specific enough that it need not be incorporated into the main library, but I thought I'd contribute it in case others found it useful. |
|
I'll also clarify that this is not an ordering on the data contained in a clist, but rather an ordering of clists themselves: i.e. how does clist a compare to clist b. Thinking of it the following way: a clist is an equivalence class of lists. If we have Ord a, then this implies Ord [a]. I think it's natural to want to lift this to Ord (CList a), but the problem is that you don't get a well-defined ordering, as choosing different lists in the equivalence class gives you different results. This can be solved by choosing a rule which picks out a canonical representative of the equivalence class, and uses that to lift the ordering. Since we have Ord [a], there are two natural choices: the minimum and the maximum. In this case I've chosen to use the minimum, and that allows Ord (Clist a). The other seemingly natural choice is to use the list returned by toList, but this is not a good choice, as we can then have a == b, but a |
Add an Ord instance for CList, and some functions which calculate ‘allRotations’ allowing only certain multiples of rotations to be used. Useful for when the CList represents something with some symmetries, but not all rotations.