g***@gmail.com
2018-10-25 01:09:52 UTC
A few thoughts on Concepts:
As Concepts have evolved, I have found it difficult to get a handle on what
Concepts actually are.
i.e.: Are Concepts functions, types, or something else?
Bjarne's CppCon 2018 talk "Concepts: The Future of Generic Programming"
answers that question clearly.
In his talk, Bjarne says:
* Concepts are NOT types of types. They are NOT type classes.
* Concepts can take more than one argument.
* Concept is a specification of what one or more types can do.
At around 1:06:30 in his talk Bjarne says:
* "it's just like defining functions, you *ARE* DEFINING FUNCTIONS".
So I want to ask:
-----
If concepts ARE functions why don't they look like functions?
Perhaps they should?
-----
The Concepts defined in Bjarne's talk look more like variable definitions
*defined* in what feels (to me) like an odd mix of logic and type like
syntax:
template<typename X> using Value_type = X::value_type;
template<typename X> using Iterator_of = X::iterator;
template<typename For, typename For2, typename Out>
concept Mergable =
ForwardIterator<For>
&& ForwardIterator<For2>
&& OutputIterator<Out>
&& Assignable<Value_type<For>,Value_type<Out>>
&& Assignable<Value_type<For2>,Value_type<Out>>
&& Comparable<Value_type<For>,Value_type<For2>>;
The above looks like a variable definition. If it is not, then is it right
that it looks like one?
It's a definition, with conditional logic et al. i.e it uses &&. etc. like
an inline function.
So why are we defining it NOT using function like snytax?
Why is this a good thing?
I find this function as a variable thing confusing to coming to terms with
what Concepts actually are.
If Concepts ARE functions as Bjarne says, why shouldn't they look and be
composed using functional notation?
It seems I'm not alone in this feeling. J. Monnon proposes this:
Type functions and beyond
An exploration of type functions and concept functions
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0844r0.html
He says: "This document proposes to extend functions to let them operate
directly on types and concepts.
The goal is to allow writing metaprogramming in the most intuitive and
consistent way with the rest of the language."
J. Monnon says:
Here is an example of a type function:
ForwardIterator IteratorType(typename T) {
// In a type function, an `if` behaves as a `if constexpr`.
if (Container(T)) // `Container` is a concept
return T::iterator;
else if (Array(T)) // `Array` is a concept
return Decay(T);
}
// On call site:
typename I = IteratorType(C);
J. Monnon says:
"A type function is always executed at compile-time. Here, it takes a type
T and returns another type that models the ForwardIterator concept. Type
functions allow a natural and straightforward notation to manipulate types."
This also justifies his comment which I emphasise: // In a type function,
an `if` behaves as a `if constexpr`.
At this time, I agree with J. Monnon's proposal. I find it intuitive and
insightful if I understand it correctly.
If J. Monnon's paper has been discussed at any length anywhere, can someone
please tell me the outcome?
His proposal appeared on Reddit at one point but attracted a near zero
response there, which stunned me.
I'd certainly like to see more commentary on that proposal here before the
next Standards meeting that is imminent.
I may be wrong, but doesn't the D language go this route also? What is so
wrong with that approach that C++ goes it's own way?
There is more I would like to say about Concepts such as why I hate the
syntax as currently proposed.
But for now, I'd really like to focus this discussion on the main elements
I've raised.
1. If concepts ARE functions, why aren't we defining and using them with
function like syntax? And using () not <>.
2. It seems J. Monnon's proposal is making the same point as I am, only
much better? Can we please address all that he proposes?
3. I feel a more formal response to J. Monnon's paper from the main
proponents of Concepts as currently defined should be made before concepts
get wired in any further in it's current direction?
I know many people would like Concepts be the marquee feature of C++20, but
to me Concepts still seem quite away from where I'd like them to be.
Even Bjarne can only 'begrudgingly live' with the current syntax.
All this flux and begrudging really doesn't suggest to me that Concepts are
ready to go for C++20.
This is even before any of my comments or J. Monnon's paper is taken into
account.
Right now, I feel that if Modules and Coroutines were the only main
features that hit for C++20, I'd be happy with that.
If people can explain why my comments are on the mark or misplaced and what
the issues are with J. Monnon's proposal, I'd be grateful.
Thanks
As Concepts have evolved, I have found it difficult to get a handle on what
Concepts actually are.
i.e.: Are Concepts functions, types, or something else?
Bjarne's CppCon 2018 talk "Concepts: The Future of Generic Programming"
answers that question clearly.
In his talk, Bjarne says:
* Concepts are NOT types of types. They are NOT type classes.
* Concepts can take more than one argument.
* Concept is a specification of what one or more types can do.
At around 1:06:30 in his talk Bjarne says:
* "it's just like defining functions, you *ARE* DEFINING FUNCTIONS".
So I want to ask:
-----
If concepts ARE functions why don't they look like functions?
Perhaps they should?
-----
The Concepts defined in Bjarne's talk look more like variable definitions
*defined* in what feels (to me) like an odd mix of logic and type like
syntax:
template<typename X> using Value_type = X::value_type;
template<typename X> using Iterator_of = X::iterator;
template<typename For, typename For2, typename Out>
concept Mergable =
ForwardIterator<For>
&& ForwardIterator<For2>
&& OutputIterator<Out>
&& Assignable<Value_type<For>,Value_type<Out>>
&& Assignable<Value_type<For2>,Value_type<Out>>
&& Comparable<Value_type<For>,Value_type<For2>>;
The above looks like a variable definition. If it is not, then is it right
that it looks like one?
It's a definition, with conditional logic et al. i.e it uses &&. etc. like
an inline function.
So why are we defining it NOT using function like snytax?
Why is this a good thing?
I find this function as a variable thing confusing to coming to terms with
what Concepts actually are.
If Concepts ARE functions as Bjarne says, why shouldn't they look and be
composed using functional notation?
It seems I'm not alone in this feeling. J. Monnon proposes this:
Type functions and beyond
An exploration of type functions and concept functions
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0844r0.html
He says: "This document proposes to extend functions to let them operate
directly on types and concepts.
The goal is to allow writing metaprogramming in the most intuitive and
consistent way with the rest of the language."
J. Monnon says:
Here is an example of a type function:
ForwardIterator IteratorType(typename T) {
// In a type function, an `if` behaves as a `if constexpr`.
if (Container(T)) // `Container` is a concept
return T::iterator;
else if (Array(T)) // `Array` is a concept
return Decay(T);
}
// On call site:
typename I = IteratorType(C);
J. Monnon says:
"A type function is always executed at compile-time. Here, it takes a type
T and returns another type that models the ForwardIterator concept. Type
functions allow a natural and straightforward notation to manipulate types."
This also justifies his comment which I emphasise: // In a type function,
an `if` behaves as a `if constexpr`.
At this time, I agree with J. Monnon's proposal. I find it intuitive and
insightful if I understand it correctly.
If J. Monnon's paper has been discussed at any length anywhere, can someone
please tell me the outcome?
His proposal appeared on Reddit at one point but attracted a near zero
response there, which stunned me.
I'd certainly like to see more commentary on that proposal here before the
next Standards meeting that is imminent.
I may be wrong, but doesn't the D language go this route also? What is so
wrong with that approach that C++ goes it's own way?
There is more I would like to say about Concepts such as why I hate the
syntax as currently proposed.
But for now, I'd really like to focus this discussion on the main elements
I've raised.
1. If concepts ARE functions, why aren't we defining and using them with
function like syntax? And using () not <>.
2. It seems J. Monnon's proposal is making the same point as I am, only
much better? Can we please address all that he proposes?
3. I feel a more formal response to J. Monnon's paper from the main
proponents of Concepts as currently defined should be made before concepts
get wired in any further in it's current direction?
I know many people would like Concepts be the marquee feature of C++20, but
to me Concepts still seem quite away from where I'd like them to be.
Even Bjarne can only 'begrudgingly live' with the current syntax.
All this flux and begrudging really doesn't suggest to me that Concepts are
ready to go for C++20.
This is even before any of my comments or J. Monnon's paper is taken into
account.
Right now, I feel that if Modules and Coroutines were the only main
features that hit for C++20, I'd be happy with that.
If people can explain why my comments are on the mark or misplaced and what
the issues are with J. Monnon's proposal, I'd be grateful.
Thanks
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/ae920b87-e062-4b2c-b74c-ae3067d3c604%40isocpp.org.
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/ae920b87-e062-4b2c-b74c-ae3067d3c604%40isocpp.org.