[proto][design]why unary_expr,binary_expr; but no nullary_expr?

Although there's unary_expr<Tag,*>, binary_expr<tag.*,*> in traits.hpp there's no nullary_expr<Tag>. I realize this would be a replacement to the current terminal template but with a user specified tag. After all, if a user specified tag for n-ary (where n>0) expressions *is* desirable, why is a user specified tag for 0-ary expressions *not* desirable? On case where this would be useful is for algebraic morphisms where n-ary ops in a source algebra are mapped to n-ary ops in a target algebra. This *includes* 0-ary ops. An op would be the equivalent to proto tags. I think this could be done by another transform similar to the pass_through transform but allowing transformation of the tag. Currently pass_through just uses the source tag in the target expression. It seems like it should be pretty easy to allow transformation on the tag also.

On 04/27/08 06:01, Larry Evans wrote: [snip]
On case where this would be Should read "one use case" useful is for algebraic morphisms where n-ary ops in a source algebra are mapped to n-ary ops in a target algebra. This *includes* 0-ary ops. An op would be the equivalent to proto tags. I think this could be done by another transform similar to the pass_through transform but allowing transformation of the tag. [snip] The attached compiles and runs an does this algebraic type morphism. Maybe one thing about the attachment is that it requires proto::expr CTOR's to be specialized to allow the mapping. Also, I'm wondering whether using something other than tag::terminal for 0-ary args, i.e. args0, will lead to problems.

Larry Evans wrote:
Although there's unary_expr<Tag,*>, binary_expr<tag.*,*> in traits.hpp there's no nullary_expr<Tag>. I realize this would be a replacement to the current terminal template but with a user specified tag. After all, if a user specified tag for n-ary (where n>0) expressions *is* desirable, why is a user specified tag for 0-ary expressions *not* desirable? <snip>
Mostly because I couldn't think of a use case at the time. There's nothing in Proto's design that would prohibit a 0-ary expression from having a tag type other than tag::terminal, but I bet there are some places in the code that make that assumption. They would all need to be hunted down and fixed. Probably not too hard. If you felt like submitting a patch (hint hint), then be sure to use branches/proto/v4 as a starting point. -- Eric Niebler Boost Consulting www.boost-consulting.com

Eric Niebler wrote:
Larry Evans wrote:
Although there's unary_expr<Tag,*>, binary_expr<tag,*,*> in traits.hpp there's no nullary_expr<Tag>. I realize this would be a replacement to the current terminal template but with a user specified tag. After all, if a user specified tag for n-ary (where n>0) expressions *is* desirable, why is a user specified tag for 0-ary expressions *not* desirable? <snip>
Mostly because I couldn't think of a use case at the time. There's nothing in Proto's design that would prohibit a 0-ary expression from having a tag type other than tag::terminal, but I bet there are some places in the code that make that assumption. They would all need to be hunted down and fixed. Probably not too hard.
This is now implemented on trunk. -- Eric Niebler BoostPro Computing http://www.boostpro.com
participants (2)
-
Eric Niebler
-
Larry Evans