|
![](/i/fill.gif) |
Orchid XP v8 <voi### [at] dev null> wrote:
> "But null pointers can be useful!" I hear you cry. For this, Haskell has
> the "Maybe" type. Basically, if you say "Foo", it will definitely,
> always, be a Foo. But if you say "Maybe Foo", then it may or may not be
> a Foo - and the type system *requires* you to explicitly check whether
> it's "null" or not before you do stuff to it.
It sounds a bit like references vs. pointers in C++: References in C++
cannot be null, they always have to point to an actual object. (Ok,
technically speaking you can force a reference to point to "null",
but that's undefined behavior, and checking if a reference is "null"
is more complicated than simply comparing it to 0 or NULL.)
Of course the limitation with C++ references is that they are const:
You cannot modify a reference to point to another object. Once a reference
has been initialized, it cannot be modified anymore. It will point to the
one and same object until its scope ends. (I'm not exactly sure now why
this was deemed as necessary.)
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |