Subject: Re: [boost] [variant] Maintainer
From: David Sankel (camior_at_[hidden])
Date: 2015-07-14 22:58:54
On Tue, Jul 14, 2015 at 7:01 AM, Larry Evans <cppljevans_at_[hidden]>
> IOW, maybe:
> variant<> is somewhat like the Zero
> 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.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk