-
Notifications
You must be signed in to change notification settings - Fork 161
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
Constructors #601
Comments
Thinking more about the method selection problem for constructors. Let us consider a constructor call
It doesn't make any real difference if there are more arguments. It is fairly easy to determine which methods are applicable, Something installed with
applies provided that The hard question is when another method installed with
is also applicable, which should we prefer? At the moment we prefer the most general method, ie the one that promises the least about the object created. Technically we choose the lowest ranked of I am coming to the view that this was a mistake (mine, I think), confusing applicability with selection. I think we should actually do the exact opposite, use the method that promises most about the object created (the highest ranked filter), since this is likely to produce the best-performing object. In the example that started this discussion, and with the libraries we have, we should make |
I just found this email from Martin Schonert which seems relevant. At that time what are now called "types" where called "kinds". This email clearly just represents one point in the discussion, since, in particular it proposes constructors that do not take the desired type as the first argument. About ConstructorsThis document describes some of my thoughts about constructors in GAP 4 as of A constructor is an operation that constructs objects. The constructor and Methods for other operations should in general not directly assemble objects What we want (in the order of importance)
The current mechanismThe current mechanism uses the One problem is, that a method is applicable if the promised kind for the The ranking mechanism implies (in the absence of explicit adjustments) that For example a method that promises a vectorspace and requires that the other In this case the correct result can only be guaranteed if a method promising An improved mechanismThe obvious improvement after the previous discussion would be to change The problem with this approach is that the interpretation of the other For example assume that that we again have two methods, one to construct a Again this is a problem with the rule that local correctness should imply More than one constructorThe main problem above is that there is a single constructor ('NewObject'), Since each constructor defines an interpretation of the arguments and each Since the constructor now determines what should be constructed (e.g., a It is also possible to let the constructor and its methods select a In order to allow introduction of new representations without changing As an example here is how the definition of the constructor for quarternions
One problem with this approach is that the kind of the result is not used for Restricting RepresentationOne wish is that the caller of a constructor should be able to restrict the I am not really certain what we want here. Do we really want to be able to Or do we rather wish to state preferences (as in This needs more discussion. SummaryI suggest that we take the following approach. There is a constructor (or a small number of constructors) for to each Each constructor places a well defined interpretation on its arguments. New constructors are created with Each method for a constructor should construct objects in a certain As far as possible the requirements for the arguments should express what is The adjustment for the ranking should include Martin. |
Actually this was the start of further discussion: constructors and families.pdf |
I've been playing with this on and off. Figuring out the correct selection order for constructors is actually horrible, Consider There are methods that guarantee a regular permutation group and methods that guarantee a natural symmetric group. Both of these are "stronger" guarantees than I still think that, more often than not, the method which makes the stronger guarantee is the one you want, but we will need to rank down some methods like the regular permutation groups constructors (also to avoid an infinite recursion). |
(Today @fingolfin pointed me to this issue.) Concerning the ranking of applicable methods of a constructor, the documentation of |
I think there is a bug in the way constructors are implemented.
I spotted this looking at the AbelianGroupCons constructor, which, when called with IsGroup as first argument does not consider the constructor installed for IsFpGroup. If it did the function AbelianGroup could be considerably simplified.
The problem is that when the methods are installed the implications of the first argument need to be filled in before it is stored (or possibly during method selection). Without implications IsFpGroup does not actually have all the filters set for IsGroup (they are implied but not explicit).
I'll take a look.
The text was updated successfully, but these errors were encountered: