-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Either
type in tact
#379
Comments
Yes, this is needed to implement #322. I'd propose to use the pipe symbol Line 24 in da6a7f6
We should also outline the concrete syntax for the constructors and destructors for the Either type. To construct an expression of an Either type, we need two constructors, we can reuse the To destruct an expression of an Either type, we need pattern-matching:
or, in Ohm.js-like notation:
This could be good enough for an initial implementation, later we could support things like |
The only problem I have with using TL-B on the other hand, makes a clear distinction with the selector bit. And because we want Tact code to interoperate with TL-B definitions, there's no way to abstract that implementation detail away. |
Well, because it is commutative. In the sense that you can always build an isomorphism between |
Yup, but serializing type X in |
Yeah, that's a good point, but still more verbose syntax won't prevent this. I'm happy to change my opinion if you have a convincing concrete example, though |
We may come up with an let foo: X or Y = ...; As a bonus it pairs nicely with More examples: // Maybe of Eithers'
let foo: (X or Y)? = ...;
// Alternative Maybe of Eithers'
let foo2: X or? Y = ...;
// Either of Maybes'
let bar: X? or Y? = ...;
// Throwing as into the mix
let baz: (X as uint64 or Y as coins)? = ...;
let baz2: X as uint64 or? Y as coins = ...; // alternative maybe of eithers' |
@novusnota what’s that in TL-B notation? |
@Gusarich Something like this, I guess: // TL-B: Either X Y
let ex1: X or Y = ...; // just the Either
// TL-B: Maybe (Either X Y))
let ex2: X or? Y = ...; // Maybe of Either's, like here:
// https://github.com/ton-blockchain/ton/blob/140320b0dbe0bdd9fd954b6633a3677acc75a8e6/crypto/block/block.tlb#L155-L157
// TL-B: Either (Maybe X) (Maybe Y)
let ex3: X? or Y? = ...; // Either of Maybe's
// TL-B: Maybe (Either (Maybe X) (Maybe Y))
let ex4: X? or? Y? = ...; // Maybe of Either of Maybe's (inception!) |
@novusnota We should just allow |
I tried to implement this, but I came across the fact that in the type |
Just remembered that Kotlin (the language we name in the first commandment of Tact) uses I'm not saying that we should have type casts (we probably don't, except for our But this is also fine:
|
Yes, obviously unsafe type casts have no place in security/finance applications.
I understand how adding |
@verytactical but the thing is that token standards have Maybe we should add some flag for that, so that it's possible to strictly check which of the |
Tact should add support for
Either
TL-B type.I propose we use the
?
operator: TL-BEither X Y
-> TactX ? Y
. If it's too confusing we could also use a more explicit syntaxEither<X, Y>
.The text was updated successfully, but these errors were encountered: