struct Some(T){
    T value;
}
struct None{}

struct Option(T){
    alias OptionAdt(T) = Algebraic!(Some!T, None);
    OptionAdt!T value; //Should default to none
    //OptionAdt!T value = OptionAdt!T(None());
    /*
Error: memcpy cannot be interpreted at compile time, because it has no
      available source code
    */
}

It is a bit unfortunate that the default value of Option!T.init is neither Some!T nor None.

Also Algebraic probably has to be wrapped in a struct because D can not infer the type of T for the following code.

alias Option(T) = Algebraic!(Some!T, None);

bool test(T)(auto ref Option!T o){
    return true;
}

I really love ADT's but I think that they can not be used as a default value limits their usefulness.

/discuss



Reply via email to