Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would I want to use the upcoming let! ... and! syntax?

The language suggestion states that the advantages are detailed in the linked paper. I had a quick skim through and I can't see it spelled out explicitly.

Is the advantage just that each statement gets executed in parallel so I might get a speed boost? Or is there some kind of logic it caters for, that is not convenient using the usual monadic let!?

I understand that, this being applicative, means that it comes with the limitation that I can't use previous expressions to determine the logic of subsequent expressions. So does that mean the trade off is flexibility for efficiency?

like image 621
Chechy Levas Avatar asked Sep 03 '20 08:09

Chechy Levas


People also ask

What is the function and syntax of let?

The LET function assigns names to calculation results. This allows storing intermediate calculations, values, or defining names inside a formula. These names only apply within the scope of the LET function. Similar to variables in programming, LET is accomplished through Excel's native formula syntax.

Why do we use let statement?

Use the LET statement to assign the value of expression to variable. See assignment statements for more information about assigning values to variables.

When you should use the new Excel let function?

The Excel LET function lets you define named variables in a formula. There are two primary reasons you might want to do this: (1) to improve performance by eliminating redundant calculations and (2) to make more complex formulas easier to read and write. name1 - First name to assign. Must begin with a letter.

Why do we need to let and const?

`const` is a signal that the identifier won't be reassigned. `let` is a signal that the variable may be reassigned, such as a counter in a loop, or a value swap in an algorithm. It also signals that the variable will be used only in the block it's defined in, which is not always the entire containing function.


1 Answers

The way I understood Don Syme's description, when I read it a while ago, was every step in the let! ... and! ... chain will be executed, unlike when you use let! ... let! .... Say, for instance, that you use the option CE. Then if you write

option {
    let! a = parseInt("a")
    let! b = parseInt("b")
    return a + b
}

only the first let! will be executed, as the CE short-circuits as soon as it meets a None. Writing instead let! a ... and! b = ... will try to parse both strings; though not necessarily in parallel, as I understand it.

I see a huge benefit in this, when parsing data from external sources. Consider for instance running

parse {
    let! name = tryParse<Name>("John Doe")
    and! email = tryParse<EMail>("johndoe@")
    and! age = tryParse<uint>("abc")
    return (name, email, age)
}

and getting an Error(["'johndoe@' isn't a valid e-mail"; "'abc' isn't a valid uint"]) in return, instead of only the first of the errors. That's pretty neat to me.

like image 92
torbonde Avatar answered Sep 26 '22 01:09

torbonde