Skip to content
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

Operator/infix function implies #36

Open
WhiteBlackGoose opened this issue Feb 23, 2022 · 3 comments
Open

Operator/infix function implies #36

WhiteBlackGoose opened this issue Feb 23, 2022 · 3 comments
Labels
Language idea One single idea which may be a start of a design document

Comments

@WhiteBlackGoose
Copy link
Member

Problem

Imagine you want to perform the following common pattern: see, that if something is valid, then if its something else is true.

For example, you want to filter out people whose name surely doesn't end with "mia", however some accounts don't have names, and you can't say anything about them:

string? name = ...
if (name is null || name.EndsWith("mia"))
    Exclude(name);

Definition

Syntax

If we're going to do literal logical operators, like and, or, etc., then the syntax should be implies.

Otherwise, it could be ==>, for example.

Meaning

The meaning of A implies B is (not A) or B.

The operator priority of it should be the lowest, even lower than equality: a + b == 0 implies a - b < 0 is (a + b == 0) implies (a - b < 0).

Under the hood

It could be either an operator or infix function. The concern with infix functions is precedence, since implies should have a very low priority.

Examples

1.

string? name = ...
if (name is notnull implies name.EndsWith("mia"))
    return "These aren't the droids you're looking for";

2.

if (input.IsValid implies input.Length > 3)
    ...
@WhiteBlackGoose WhiteBlackGoose added the Language idea One single idea which may be a start of a design document label Feb 23, 2022
@yamin8000
Copy link

however some accounts don't have names

Does that mean name is null for them?
I may not fully understand your purpose for this operator/infix function, but is this similar to how safe method calls work in Kotlin?
Or maybe safe calls are only subset of this operator functionality?

@WhiteBlackGoose
Copy link
Member Author

Does that mean name is null for them?

Yes

I may not fully understand your purpose for this operator/infix function, but is this similar to how safe method calls work in Kotlin?

Not really, though monadic nullables is imo a must for Fresh.

It's basically just a boolean operator, like and/&& and things, it's just its truth table looks like

a b and or implies
0 0 0 0 1
0 1 0 1 1
1 0 0 1 0
1 1 1 1 1

@pxeger
Copy link

pxeger commented Mar 5, 2022

I don't see any point in this, when you can just use (not a) or b which is clearer and doesn't add an extra feature to maintain. It just adds extra cognitive load, and one more thing new users have to learn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Language idea One single idea which may be a start of a design document
Projects
None yet
Development

No branches or pull requests

3 participants