-
Notifications
You must be signed in to change notification settings - Fork 10
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
Concatenation of ordered types #4
Comments
Good point @cmacmackin, however
I do not completely understand this issue. In particular why using
Also for this point an example can help me to understand you.
When dealing with abstracts, at some point, I think it is very difficult to avoid type-guards, at least for not so trivial algorithms. Indeed, I feel that the necessity to add type-guards will be not so hurting, it will clutter the sources, but not so hurting.
I think it could be preferable to have it in
This is where I am lost. Why keeping Cheers |
Putting some more thought into this, I can see that it isn't inherently necessary to know the low-level details of the Efficiency, however, still represents some obstacles. Let's take the example of a list, constructed from an array. In that case, I'm pretty sure the mot efficient (as in, quickest to run) way to concatenate two objects would be to create a new array from the existing two. However, in order to do that, you need to know the low-level details of the types. You could just use Ultimately, I suspect that the best solution is to use type-guards to allow the concatenation to be performed efficiently if |
I think so, not sure if it is a golden rule.
What is intriguing me that type-guard is necessary if the
I agree, but for such a generic container some performance penalties must be taken into account. It would be nice to have a mechanism to immediately identify methods that are potentially not efficient, e.g. a naming conventions that alert users that method |
I am borrowing from .Net again, here, but it seems that you could store a description of the underlying type in the container class and expose it with a GetType() function? Type information might then be made available to the ordered class using syntax like rhs%Index()%GetType()? |
That sounds like a good approach. I don't think I'll go as far as a On 16-02-26 07:20 PM, SourcerersApprentice wrote:
Chris MacMackin |
Pardon my collision of C# and Fortran style. |
I'd originally intended to overload the concatenation operator for ordered data types. This was to be done by creating a deffered type-bound procedure in the abstract
ordered
type, like below:One consequence is that this means that the returned, concatenated, object must be an allocatable abstract type. In some cases that can be useful, but in others it's a pain because it would require type-guards to assign it to a variable of the actual type.
Another problem is the question of the ordering of the concatenation. My preference would be to order it such that using the
pop()
method to iterate through the returned object would function as thoughpop()
had been used to iterate through thelhs
object and then to iterate through therhs
object. However, doing this requires knowledge of the internal structure of the derived type, which is not available if the interface makes the objectclass(ordered)
. Furthermore, the concatenation can be performed much more efficiently if you act on the internal structure of the derived type directly, rather than just accessing it through the (rather few) methods available forclass(ordered)
objects.One possibility would be to remove the method definition from
ordered
and place separate definitionsin each concrete derived type. This, of course, would mean that it can't be used in a polymorphic manner. Another possibility would be to keep the definition in the
ordered
type and use type-guards in each implementation. This would potentially be quite time consuming.Thoughts?
The text was updated successfully, but these errors were encountered: