ethereum / moon-lang

Minimal code-interchange format
MIT License
193 stars 20 forks source link

Replace Let term with Map? #12

Closed AnthonyJacob closed 7 years ago

AnthonyJacob commented 7 years ago

Why does moon-core contain Let constructor when it also has Map?

Both gives names to expressions. But Map can also group multiple expressions under the same name, providing a simple module system.

VictorTaelin commented 7 years ago

Because let is translated to local variables in functions and is thus orders of magnitude faster than maps. The reason let is usually needed in functional languages is to preserve sharing after beta-reduction. Note that if we didn't have let, the proper way to express it would be with lambdas, i.e., let x = y in z would be represented by ((x => z) y).

AnthonyJacob commented 7 years ago

Could private keyword solve that?

x = { 
private fooo a b c = ... ,
foo a = fooo a " " ", " ,
}
x.fooo "a b c" " " ", " // throws an error, x does not have field fooo
x.foo "a b c" // returns "a, b, c"

In reality I would be for something less verbose, for example every name prefixed with _ would be private (eg _foo is private).

VictorTaelin commented 7 years ago

That doesn't make a lot of sense to me, sorry :( I think let is great on the short term. On the long term it will be replaced by (a => b) c.

AnthonyJacob commented 7 years ago

On the long term it will be replaced by (a => b) c.

Isnt that possible only with optimal evaluation strategy? Are we going to use Lamping's abstract algorithm for that?

VictorTaelin commented 7 years ago

Possible in what sense? I think removing let would be ok even with just closures. But for example, without let, how we can represent sharing on terms on normal form? It is important to represent sharing.

AnthonyJacob commented 7 years ago

On the long term it will be replaced by (a => b) c.

I mean, why would you remove let and replace it with apply, if (as you said) we need let for sharing!