Pandas like features

jmh530 john.michael.hall at gmail.com
Mon Oct 26 19:39:54 UTC 2020


On Sunday, 25 October 2020 at 21:30:59 UTC, jmh530 wrote:
> [snip]
>
> I think, unfortunately, it is not always easy to communicate 
> why these changes are important or valuable. But, while you 
> weren't able to convince Atila of the value of the proposed 
> features, I also don't think you were ignored either, at least 
> in that case.
>
> That being said, I never understood Atila's argument about this 
> feature as being a light version of Rust traits (I'm not aware 
> of how Haskell's typeclasses work). A Rust trait is a list of 
> functions that must be implemented by a type. However, you can 
> also statically dispatch based on the trait (you can 
> dynamically as well, but I imagine you would prefer not to be 
> able to do that). You conceivably would be more interested in 
> the static dispatch part of it. It's not really about a 
> PackedUpperTriangularMatrix requiring specific functions to be 
> a PackedUpperTriangularMatrix rather than a Slice. All it takes 
> is the right iterator type. So it's more about how the specific 
> type is specialized (giving a specific iterator to 
> PackedUpperTriangularMatrix).
>
> There might be a way to create a feature that's not Rust traits 
> that does what you want and is a more general feature than this 
> type of template alias deduction.

Adding a little more...

The situation that this issue is trying to address is something 
like a template
T!(U!V)
that you want to be able to use like
W!V.

I can't help but think that concepts could help with this 
situation. Adapting the C++20 syntax, consider this simplest 
implementation:

template PackedUpperTriangularMatrix(T)
{
     concept PackedUpperTriangularMatrix = is(T: 
Slice!(StairsIterator!(U*, "-")), U);
}

Assuming the same functionality as in C++20, you could use this 
in a function as in
void foo(PackedUpperTriangularMatrix x) {}

However, if you then want to place any constraints on the U 
above, then you're a bit SOL.

To really get the functionality working, you would need a generic 
kind of concept, where the concept you are defining is itself 
generic.
As far as I can tell, you can't do this with C++20, but I would 
imagine the syntax adapted from above might be something like

template PackedUpperTriangularMatrix(T)
{
     concept PackedUpperTriangularMatrix(U) = is(T: 
Slice!(StairsIterator!(U*, "-")));
}

and would enable you to write the function as
void foo(T)(PackedUpperTriangularMatrix!T x) {}

In other words, if D had the ability to define concepts that are 
also generic themselves, then it would enable the functionality 
you want also.


More information about the Digitalmars-d mailing list