
Hi, Is there any interest for a "Maybe" utility class, like the one in Haskell ? For those who don't know about Maybe, here is the Haskell ref : http://www.haskell.org/ghc/docs/6.10.4/html/libraries/base/Prelude.html#t%3A... And a code snippet showing its use : http://pastebin.com/m3a590d6e Arnaud

2009/12/20 Arnaud Masserann <arnaud1602@gmail.com>:
Is there any interest for a "Maybe" utility class, like the one in Haskell ?
Is that any different from Boost.Optional? http://boost.org/libs/optional

On Sun, Dec 20, 2009 at 6:48 PM, Arnaud Masserann <arnaud1602@gmail.com> wrote:
Hi,
Is there any interest for a "Maybe" utility class, like the one in Haskell ?
For those who don't know about Maybe, here is the Haskell ref : http://www.haskell.org/ghc/docs/6.10.4/html/libraries/base/Prelude.html#t%3A... And a code snippet showing its use : http://pastebin.com/m3a590d6e
It looks like Boost.Optional from how it is used in your pastebin snippet. How is it different from Boost.Optional?

On Sun, Dec 20, 2009 at 7:11 PM, OvermindDL1 <overminddl1@gmail.com> wrote:
On Sun, Dec 20, 2009 at 6:48 PM, Arnaud Masserann <arnaud1602@gmail.com> wrote:
Hi,
Is there any interest for a "Maybe" utility class, like the one in Haskell ?
For those who don't know about Maybe, here is the Haskell ref : http://www.haskell.org/ghc/docs/6.10.4/html/libraries/base/Prelude.html#t%3A... And a code snippet showing its use : http://pastebin.com/m3a590d6e
It looks like Boost.Optional from how it is used in your pastebin snippet. How is it different from Boost.Optional?
For example, here is your snippet, copied and altered to use the Boost.Optional form: http://pastebin.com/m24a84c01 How is Maybe different? Does it introduce any extra functionality?

As a matter of fact, none :) The weird thing here is that google "boost maybe" or even "boost maybe haskell" don't return anything, but here's an excerpt from Boost.Optional ref : " There is precedent for a discriminated union as a model for an optional value: the Haskell <http://www.haskell.org/> *Maybe* built-in type constructor. Thus, a discriminated union T+nil_t serves as a conceptual foundation. " Anyway, glad to hear it exists :) Arnaud On Mon, Dec 21, 2009 at 3:21 AM, OvermindDL1 <overminddl1@gmail.com> wrote:
On Sun, Dec 20, 2009 at 7:11 PM, OvermindDL1 <overminddl1@gmail.com> wrote:
On Sun, Dec 20, 2009 at 6:48 PM, Arnaud Masserann <arnaud1602@gmail.com> wrote:
Hi,
Is there any interest for a "Maybe" utility class, like the one in Haskell ?
For those who don't know about Maybe, here is the Haskell ref :
http://www.haskell.org/ghc/docs/6.10.4/html/libraries/base/Prelude.html#t%3A...
And a code snippet showing its use : http://pastebin.com/m3a590d6e
It looks like Boost.Optional from how it is used in your pastebin snippet. How is it different from Boost.Optional?
For example, here is your snippet, copied and altered to use the Boost.Optional form: http://pastebin.com/m24a84c01
How is Maybe different? Does it introduce any extra functionality? _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

On 12/20/09 20:11, OvermindDL1 wrote:
On Sun, Dec 20, 2009 at 6:48 PM, Arnaud Masserann <arnaud1602@gmail.com> wrote:
Hi,
Is there any interest for a "Maybe" utility class, like the one in Haskell ?
For those who don't know about Maybe, here is the Haskell ref : http://www.haskell.org/ghc/docs/6.10.4/html/libraries/base/Prelude.html#t%3A... And a code snippet showing its use : http://pastebin.com/m3a590d6e
It looks like Boost.Optional from how it is used in your pastebin snippet. How is it different from Boost.Optional?
Boost Optional looks like variant with a single component and *without* the never empty guarantee: http://www.boost.org/doc/libs/1_41_0/doc/html/variant/design.html#variant.de... Instead of Optional, why not adapt variant to do both what variant does and what optional does? All that would be required is simply allowing an empty variant which could always be detected with a test for which() == -1.

On Sun, Dec 20, 2009 at 7:30 PM, Larry Evans <cppljevans@suddenlink.net> wrote:
On 12/20/09 20:11, OvermindDL1 wrote:
On Sun, Dec 20, 2009 at 6:48 PM, Arnaud Masserann <arnaud1602@gmail.com> wrote:
Hi,
Is there any interest for a "Maybe" utility class, like the one in Haskell ?
For those who don't know about Maybe, here is the Haskell ref :
http://www.haskell.org/ghc/docs/6.10.4/html/libraries/base/Prelude.html#t%3A... And a code snippet showing its use : http://pastebin.com/m3a590d6e
It looks like Boost.Optional from how it is used in your pastebin snippet. How is it different from Boost.Optional?
Boost Optional looks like variant with a single component and *without* the never empty guarantee:
http://www.boost.org/doc/libs/1_41_0/doc/html/variant/design.html#variant.de...
Instead of Optional, why not adapt variant to do both what variant does and what optional does? All that would be required is simply allowing an empty variant which could always be detected with a test for which() == -1.
Actually optional is pretty near to being exactly: optional<T> == variant<nil_t,T> And an easier accessor function of course.

OvermindDL1 wrote:
Actually optional is pretty near to being exactly: optional<T> == variant<nil_t,T> And an easier accessor function of course.
Easier *and* faster, since "dereferencing" (via unary operator* or get) only asserts that the optional is initialized, hence doesn't need to access its initialization state bit. As far as I know, Boost.Variant always needs to access its "which" state. - Jeff
participants (5)
-
Arnaud Masserann
-
Jeffrey Hellrung
-
Larry Evans
-
OvermindDL1
-
Scott McMurray