On Friday, 6 November 2020 at 10:51:20 UTC, Andrey Zherikov wrote:
struct Result(T)
{
struct Success
{
static if(!is(T == void))
{
T value;
}
}
struct Failure
{
string error;
}
Algebraic!(Success, Failure) result;
this
On Saturday, 7 November 2020 at 15:49:13 UTC, James Blachly wrote:
```
return i > 0 ? cast(Result) Success!int(i) : cast(Result)
Failure("Sorry");
```
I don't know about the SumType but I would expect you could use a
construction instead of cast.
import std;
alias Result = Algebraic!
On Saturday, 7 November 2020 at 15:49:13 UTC, James Blachly wrote:
```
retval = i > 0 ? Success!int(i) : Failure("Sorry");
```
casting each to `Result` compiles, but is verbose:
```
return i > 0 ? cast(Result) Success!int(i) : cast(Result)
Failure("Sorry");
```
** Could someone more kno
On 11/6/20 5:51 AM, Andrey Zherikov wrote:
I have auto function 'f' that might return either an error (with some
text) or a result (with some value). The problem is that the type of the
error is not the same as the type of result so compilation fails.
...
How can I make the original code comp
On Saturday, 7 November 2020 at 01:50:15 UTC, Jesse Phillips
wrote:
On Friday, 6 November 2020 at 15:06:18 UTC, Andrey Zherikov
wrote:
On Friday, 6 November 2020 at 14:58:40 UTC, Jesse Phillips
wrote:
On Friday, 6 November 2020 at 14:20:40 UTC, Andrey Zherikov
wrote:
This issue seems hit the in
On Friday, 6 November 2020 at 15:06:18 UTC, Andrey Zherikov wrote:
On Friday, 6 November 2020 at 14:58:40 UTC, Jesse Phillips
wrote:
On Friday, 6 November 2020 at 14:20:40 UTC, Andrey Zherikov
wrote:
This issue seems hit the inability to implicitly convert
custom types. May be it makes more sen
On Friday, 6 November 2020 at 20:05:36 UTC, Ferhat Kurtulmuş
wrote:
On Friday, 6 November 2020 at 10:51:20 UTC, Andrey Zherikov
wrote:
I have auto function 'f' that might return either an error
(with some text) or a result (with some value). The problem is
that the type of the error is not the
On Friday, 6 November 2020 at 10:51:20 UTC, Andrey Zherikov wrote:
I have auto function 'f' that might return either an error
(with some text) or a result (with some value). The problem is
that the type of the error is not the same as the type of
result so compilation fails.
[...]
Sounds li
On Friday, 6 November 2020 at 15:06:18 UTC, Andrey Zherikov wrote:
To clarify my statement:
Yes, Result!void and Result!int are different types but I
couldn't find a way to implicitly convert one to another.
You can't. Structs do not implicitly convert to each other,
templated or otherwise.
On Friday, 6 November 2020 at 14:58:40 UTC, Jesse Phillips wrote:
On Friday, 6 November 2020 at 14:20:40 UTC, Andrey Zherikov
wrote:
This issue seems hit the inability to implicitly convert
custom types. May be it makes more sense to ask in a separate
thread.
The return type must be the same
On Friday, 6 November 2020 at 14:20:40 UTC, Andrey Zherikov wrote:
On Friday, 6 November 2020 at 12:03:01 UTC, Paul Backus wrote:
You can't. Both return values have to have the same type,
which means the failure function has to be able to return more
than one type, which means it has to be a te
On Friday, 6 November 2020 at 12:03:01 UTC, Paul Backus wrote:
You can't. Both return values have to have the same type, which
means the failure function has to be able to return more than
one type, which means it has to be a template.
This issue seems hit the inability to implicitly convert c
On Friday, 6 November 2020 at 13:59:58 UTC, gbram wrote:
On Friday, 6 November 2020 at 12:03:01 UTC, Paul Backus wrote:
On Friday, 6 November 2020 at 10:51:20 UTC, Andrey Zherikov
wrote:
How can I make the original code compilable without
templatizing `failure` function?
You can't. Both ret
On Friday, 6 November 2020 at 12:03:01 UTC, Paul Backus wrote:
On Friday, 6 November 2020 at 10:51:20 UTC, Andrey Zherikov
wrote:
How can I make the original code compilable without
templatizing `failure` function?
You can't. Both return values have to have the same type, which
means the fa
On Friday, 6 November 2020 at 10:51:20 UTC, Andrey Zherikov wrote:
I can make it work if I add a type to `failure` function but
this remove brevity in usage:
-
auto failure(T)(string error)
{
return Result!T(Result!T.Failure(error));
}
auto f(int i)
{
return i > 0 ? succe
15 matches
Mail list logo