August 20, 2018
On Monday, 20 August 2018 at 19:06:36 UTC, Seb wrote:
> [snip]
> That looks pretty cool!
> I added optional to run.dlang.io (e.g. https://run.dlang.io/is/912kVG) and the project tester (https://github.com/dlang/ci/pull/288).

It's interesting that both sumtype and optional have match templates. Maybe scope to combine these projects?
August 22, 2018
On Monday, 20 August 2018 at 19:52:53 UTC, jmh530 wrote:
> On Monday, 20 August 2018 at 19:06:36 UTC, Seb wrote:
>> [snip]
>> That looks pretty cool!
>> I added optional to run.dlang.io (e.g. https://run.dlang.io/is/912kVG) and the project tester (https://github.com/dlang/ci/pull/288).
>
> It's interesting that both sumtype and optional have match templates. Maybe scope to combine these projects?

That'd be cool. Optional uses .match on a "some" or "none" range, while SumType uses it on a union. So ideas on how to go about it?
August 22, 2018
On Wednesday, 22 August 2018 at 22:11:05 UTC, aliak wrote:
> On Monday, 20 August 2018 at 19:52:53 UTC, jmh530 wrote:
>>
>> It's interesting that both sumtype and optional have match templates. Maybe scope to combine these projects?
>
> That'd be cool. Optional uses .match on a "some" or "none" range, while SumType uses it on a union. So ideas on how to go about it?

In theory, Optional(T) could be implemented as a wrapper around SumType!(T, None), which would let it reuse SumType's match method. I'm not sure if it'd be worth the effort to convert at this point, though.
August 24, 2018
On Wednesday, 22 August 2018 at 22:49:52 UTC, Paul Backus wrote:
> On Wednesday, 22 August 2018 at 22:11:05 UTC, aliak wrote:
>> On Monday, 20 August 2018 at 19:52:53 UTC, jmh530 wrote:
>>>
>>> It's interesting that both sumtype and optional have match templates. Maybe scope to combine these projects?
>>
>> That'd be cool. Optional uses .match on a "some" or "none" range, while SumType uses it on a union. So ideas on how to go about it?
>
> In theory, Optional(T) could be implemented as a wrapper around SumType!(T, None), which would let it reuse SumType's match method. I'm not sure if it'd be worth the effort to convert at this point, though.

THis is true. And might be interesting to try out actually. Can you access the types in a SumType via index?

I'm thinking because Optional behaves like a range, and I guess I'd define a SumType!(T, None), then a rough outline may be:

struct None {}
immutable none = None();

struct(T) {
  SumType(T, None) opt;
  T front() {
    return opt[0]; // what to do here?
  }
}

Or I guess I should maybe do it like this?:

return opt.match!(
  (T val) => val,
  (None) => T.init,
);




August 24, 2018
On Friday, 24 August 2018 at 20:59:34 UTC, aliak wrote:
> THis is true. And might be interesting to try out actually. Can you access the types in a SumType via index?
>
> I'm thinking because Optional behaves like a range, and I guess I'd define a SumType!(T, None), then a rough outline may be:
>
> struct None {}
> immutable none = None();
>
> struct(T) {
>   SumType(T, None) opt;
>   T front() {
>     return opt[0]; // what to do here?
>   }
> }
>
> Or I guess I should maybe do it like this?:
>
> return opt.match!(
>   (T val) => val,
>   (None) => T.init,
> );

I think this is probably the best way:

@property T front() {
    return opt.match!(
        (T val) => val,
        (None) {
            assert(false, "called .front on an empty range");
            return T.init; // for return type inference
        }
    );
}

You could also do it with `tryMatch` and `std.exception.assertNotThrown`. It makes the code a little nicer, but involving exceptions at all seemed like unnecessary overhead to me.
August 27, 2018
> - Consider a short form for "dispatch". Purely for convenience:
>    e.g.: john.d.residence.d.numberOfRooms;

Why not .get, like Nullable?
As long as you never alias it to this... ;)
August 27, 2018
On Monday, 27 August 2018 at 05:22:30 UTC, FeepingCreature wrote:
>> - Consider a short form for "dispatch". Purely for convenience:
>>    e.g.: john.d.residence.d.numberOfRooms;
>
> Why not .get, like Nullable?
> As long as you never alias it to this... ;)

Mmm... get is indicative of getting the value. But we're not getting a value here, we're dispatching/propagating to the underlying type. I just wish we could figure out some way to use operators to some degree in D :(
1 2
Next ›   Last »