News for hackers. Stuff that matters.
Re:Why Rust? [pdf] by AnimalMuppet on Wednesday September 09, 2015 @03:23PM (#10193672)
> It's different from a traditional Option type, though, in that Option<Option<T>> is inexpressible.

I don't think so. It's just a pointer to a pointer, rather than a single pointer. That is,

  int **value;
and either

   value == null
or

  *value == null
or

  **value == some value of interest
Re:Why Rust? [pdf] by tomp on Wednesday September 09, 2015 @03:56PM (#10194066)
Hm... not really.

Say you have a function, `f : (bool, T) -> Option<T>`.

    function f<T>(cond : bool, value : T) : Option<T> {
      if cond {
        return value                 // equivalent: Some(value)
      } else {
        return null                  // equivalent: None
      }
    }

    let x = f(false, f(false, 1))    // equivalent: None
    let y = f(true, f(false, 1))     // equivalent: Some(None)
There is no way to tell apart `x` and `y`.
Re:Why Rust? [pdf] by dllthomas on Wednesday September 09, 2015 @04:40PM (#10194421)
You are confusing types and representations, and your function is not well typed.
Re:Why Rust? [pdf] by tomp on Wednesday September 09, 2015 @05:24PM (#10194726)
> You are confusing types and representations

Hm... not sure if I am. Or, at least, `null or T` is not a valid representation for type `Option<T>`. It's all very confusing.

> and your function is not well typed.

How so?

Re:Why Rust? [pdf] by dllthomas on Wednesday September 09, 2015 @07:10PM (#10195269)
The `value` you are returning has type T. T is not the same type as Optional<T>.

With AnimalMuppet's approach, you would need to return a pointer to a T (so, `&value` in something Cish). Note that this is not the same thing as a nullable reference in, for instance, C#.

`null or T` is a valid representation only when T is a non-nullable reference. It doesn't work when T is optional, and it also doesn't work when T is a primitive type, a struct, &c.

That said, there's obvious reasons it might be wanted an optimization where it's possible. For that specific case, `Just value` could be specialized to `value`, but that can be done by the compiler (akin to automatic unboxing, elsewhere).

Re:Why Rust? [pdf] by sanderjd on Wednesday September 09, 2015 @03:41PM (#10193888)
Yeah, I'm curious about this too. It seems like (continuing to use Rust parlance) your three examples are (respectively) `None`, `Some(None)`, and `Some(Some(some value of interest))`. There is no `None(None)` case, so there's no problem.
Re:Why Rust? [pdf] by Veedrac on Wednesday September 09, 2015 @03:47PM (#10193967)
This is fair. I was thinking of this in the context of GC'd languages, where one instead has nullable types (or sentinel null values). Eg. Java, C#, Python, Ruby, Scala.

The C++ case where a distinction between `foo = null` and `*foo = null` exists is indeed much closer to a an option type. You're right to point it out.