On Tue, Jul 14, 2015 at 7:01 AM, Larry Evans
IOW, maybe: variant<> is somewhat like the Zero and tuple<> is somewhat like the One in that haskellforall page.
Just thought it interesting, but I've no idea if Zero or One would be useful in c++. Anyone have any ideas about how they would be useful?
Heh, thanks for the fun observation Larry. I think the extension of this principle is: - given a binary function (say one of these is called 'foo') - if that function forms a monoid with some empty element 'bar' - then construct a syntax where - meaning( foo() ) = bar - meaning( foo( a, b ) ) = foo( meaning(a), meaning(b) ) - meaning( foo( a₁, a₂, …, aₙ ) ) = foo( meaning(a₁), foo( meaning( a₂ ), … meaning( aₙ ) ) … ) so if + and * have the normal arithmetic meanings and are prefix functions (not operators), we would have meaning( +( +(), 3 ) ) = 0 + 3 meaning( *( *(), 3 ) ) = 1 * 3 Of course we get the extension to binary type functions which are monoids. These include the sum type (variant) and the product type (tuple). I wonder which other common binary type functions are monoids. Another interesting thing would be a free function 'append' which appends strings together. That would imply that 'append()' is the empty string. -- David