Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2003-09-02 20:58:55


Joel de Guzman <djowel_at_[hidden]> wrote in message news:00c301c370f0$973c4fc0$8ca245ca_at_godzilla...
> Mat Marcus <mmarcus-boost_at_[hidden]> wrote:
> > --On Monday, September 01, 2003 3:37 PM -0300 Fernando Cacciola
> > <fernando_cacciola_at_[hidden]> wrote:
> >
> >> Joel de Guzman <djowel_at_[hidden]> wrote in message
> >>> One can think of an optional<T> as conceptually a specialized but
> >>> nevertheless, *IS-A* T, with the added specialization that it can
> >>> be in a dead-uninitialized state. Maybe we'll call it a zombie
> >>> object, undead object, you name it ;-)
> >
> > Hmmm. I'm not so sure about this. When I hear the phrase optional<T>
> > IS-A T with an added specialization I am reminded of the phrase a
> > Square IS-A Rectangle with an added specialization which usually gets
> > folks into trouble. [Theoretical aside: I still see optional<T> as a
> > sum/union, e.g. T + nil/ T | nil. That is I don't think we really want
> > A + B < B (the sum/union of A and B) to be a subtype of A.]
>
> This is the model that I was trying to *sell* from the very very start when
> optional first came out for review.

And it is a good model indeed, which I liked from the very moment
you mentioned it.

> I never really understood why people
> didn't see it that way. This is exactly the reason why I suggested looking
> at other languages: to be able to get a solid grasp of the concepts behind
> such a *thing* so as to be able to answer with utmost certainty the question:
> : what is optional?
>
> Some people say it is a container. Not!
>
Why?
What's wrong with saying that an object of optional<T> *contains*
an object of type T or is empty?

The fact that Haskell doesn't model it this way, or that a discriminated
union, T+nil, is a good model, doesn't mean that the container model is wrong.

I don't see any significant advantage with the union model over the container
model, and in fact, the union model implies the explicit usage of 'nil', something
I don't find particularly convenient.

> Some people say it is like a pointer
> that can be NULL. Not!

Here I agree.

> And this uncertainty leads us to confusion, and,
> ultimately: missguided syntax and semantics.
>
And you know here I disagree.. but let's leave this out.

> [snipped]
> I never really understood why I wasn't able to sell the idea that an
> optional<T> is *REALLY REALLY REALLY* nothing else but a
> union of T and nil.
>
You did sell the idea that it can be a union, but I held to the idea that
it can just as well be considered as *REALLY REALLY REALLY*
nothing else but a container that has a T or is empty.

I agree there is nothing wrong with the union model, but I don't see
why is it better than the other.

> [snipped]
>
> I would certainly hope to hear more from you. In fact,
> I wish to hear more from the type-theory people such as Mat and Vesa
> ;-)
>
I adhere to this wish!

Fernando Cacciola


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk