# Talk:Let expression

Sorry ran out of time to complete this.

My intent is to rearrange existing content out of existing pages that logically belongs together. I am a bit short of references at the moment, which I will attempt to correct. I will try to find time to add references, and go though and correct any problems.

I have re-appropriated an existing page which had a redirect through to Scope (computer science). I think the let expression has more significance in its own right, being the stepping stone through from lambda calculus through to modern functional language.

It is also significant as a construct for a named function, with restricted scope. This is significant because it avoids the problems involved in defining an anonymous function (see Curry's paradox).

I appreciate that the page is still a bit short on background, explanation and references. It also doesn't yet all fit nicely together.

Thepigdog (talk) 15:06, 27 March 2014 (UTC)

Thepigdog (talk) 10:27, 28 March 2014 (UTC)

That little problem has bothered me for a long time.

Thepigdog (talk) 04:06, 29 March 2014 (UTC)

## Notes on the problem

The result needed is,

${\displaystyle x\not \in \operatorname {FV} (y)\to (\operatorname {let} x:x=y\operatorname {in} z)=z[x:=y]}$

${\displaystyle (\exists xE\land F)\implies \operatorname {let} x:E\operatorname {in} F}$

then,

${\displaystyle \operatorname {let} x:E\operatorname {in} F}$
${\displaystyle =\operatorname {let} x:\operatorname {true} =E\operatorname {in} \operatorname {true} \land F}$
${\displaystyle =E\land F}$

So no point fiddling around with that. May as well start with,

${\displaystyle (\exists xE\land F)\iff \operatorname {let} x:E\operatorname {in} F}$

and derive,

${\displaystyle x\not \in \operatorname {FV} (y)\to (\operatorname {let} x:x=y\operatorname {in} z)=z[x:=y]}$

The awkward thing is why doesn't this rule apply for Boolean F,

${\displaystyle x\not \in \operatorname {FV} (E)\land x\in \operatorname {FV} (F)\to (\operatorname {let} x:G\operatorname {in} E\ F=E\ (\operatorname {let} x:G\operatorname {in} F))}$

It applies for all other types, why not Boolean. Why do we need to use,

${\displaystyle x\not \in \operatorname {FV} (E)\land x\in \operatorname {FV} (F)\to (\operatorname {let} x:G\operatorname {in} E\ F\to E\ (\operatorname {let} x:G\operatorname {in} F))}$

for Boolean. And then is there some problem still hiding in the woodwork here.

Its not the only rule that applies only to Boolean,

${\displaystyle (\exists xE\land F)\iff \operatorname {let} x:E\operatorname {in} F}$

only makes sense if F is Boolean. What I am worried about is the derivation,

${\displaystyle \neg (E\land F)}$
${\displaystyle \equiv \neg \operatorname {let} x:E\operatorname {in} F}$
${\displaystyle \equiv \operatorname {let} x:E\operatorname {in} \neg F}$ ...... if lifting was allowed for Boolean F.
${\displaystyle \equiv E\land \neg F}$

which is not true. The second problem that concerns me is if we could somehow counterfeit the Boolean type with another Boolean type that behaved like Boolean but was not Boolean. But then we would not have the rule applying if F was not actually of Boolean type.

${\displaystyle (\exists xE\land F)\iff \operatorname {let} x:E\operatorname {in} F}$

The argument is the you need both rules to create the contradiction.

${\displaystyle (\exists xE\land F)\iff \operatorname {let} x:E\operatorname {in} F}$

Only applies if F is Boolean, so by not allowing,

${\displaystyle x\not \in \operatorname {FV} (E)\land x\in \operatorname {FV} (F)\to (\operatorname {let} x:G\operatorname {in} E\ F=E\ (\operatorname {let} x:G\operatorname {in} F))}$

when F is Boolean, the contradiction is blocked. So I think it's OK. References ...

Thepigdog (talk) 02:09, 31 March 2014 (UTC)

## Narrowing

Narrowing is under construction.

Thepigdog (talk) 04:46, 9 April 2014 (UTC)

## Another draft

The notation has changed from (c, v) to (v, l). c was a condition and now l is a set from which a condition is calculated. The order swapped around because it went (c, v) -> (c, v, l) -> (v, l). Anyway it was originally the wrong way round.

Using the list l as data to calculate the condition makes the function application rule less intuitive. I am not really happy about that. But it helps with describing narrowing, and removes the need for other handwaving.

Narrowing is described here within math, when it is really meta programming about math. Its a bit of a shoe horn to make it work in math. And then it is not completely clear how the narrowing is applied in meta programming.

Clear ideas in natural language, translated into math, get twisted around. There is no object identity other than the value that may be used. This is frustrating because the narrowing process is simpler than can be written in math. You don't write math, math writes you.

A lot of checking and examples still needed.

Thepigdog (talk) 19:59, 12 April 2014 (UTC)

## Probabilistic value sets

Under construction.

Thepigdog (talk) 12:04, 13 April 2014 (UTC)

## Value sets and probabilistic value sets

Moved to a new article Narrowing of algebraic value sets.

It was getting too big and was no longer a good fit with let expressions.

Thepigdog (talk) 12:47, 13 April 2014 (UTC)

## Problem with local scope

There is a problem if let expressions are considered to have local scope. It is basically the same problem as with lambda expressions. An expression,

${\displaystyle (2\cdot \operatorname {let} x^{2}=4\operatorname {in} x)=(\operatorname {let} x^{2}=4\operatorname {in} x)+(\operatorname {let} x^{2}=4\operatorname {in} x)}$

This is OK if the scope of x is the whole expression. But if x was considered to have a scope local to the let expression, then x could be renamed to y,

${\displaystyle (2\cdot \operatorname {let} x^{2}=4\operatorname {in} x)=(\operatorname {let} x^{2}=4\operatorname {in} x)+(\operatorname {let} y^{2}=4\operatorname {in} y)}$

which is no longer true. Not sure how to best deal with this as in common usage in functional languages the let expression is considered to define a function with local scope.

Thepigdog (talk) 03:59, 23 May 2014 (UTC)