Implicit conversion from 'Ok' to 'Result' type when returning functions

David Zhang via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 21 02:55:41 PDT 2017


On Sunday, 21 May 2017 at 09:37:46 UTC, Nicholas Wilson wrote:
> On Sunday, 21 May 2017 at 09:29:40 UTC, David  Zhang wrote:
> Well then it becomes
>  Result!(T, E) ok(T,E)     (T t) { return Result(t); }
>  Result!(T, E) error(T,E)(E e) { return Result(e); }
>
> and then provided it can be inferred (e.g. from the function 
> signature)
> it will still work.

But how would it be inferred? Like the `ok` function, `T` could 
be inferred, but E? I'm not sure I understand. If you have to 
specify the types every time, it kinda defeats the purpose. With 
the function signature as it is, you'd have to specify the type 
of the other type (e.g. you'd need to specify E for `ok()`).


More information about the Digitalmars-d-learn mailing list