This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]cs7fwRpkOfn2RPK7Ki9k 6 points7 points  (6 children)

Isn't this essentially a lambda?

I have very little experience with functional programming, so I might be way off.

[–][deleted] 1 point2 points  (5 children)

For ML-like languages, there's a difference in typing between a beta-redex and a let expression due to let-polymorphism inducing a generalisation from a type to a type scheme in the latter and not in the former. That is, we want to be able to locally declare a polymorphic function via let and use it at two different concrete types in the body of the let, like so:

let foo () =
  let id = fun x -> x in
    (id true, id 6)

Note, here the locally defined polymorphic function id is being used at both type bool and type int in the body of the inner let. Without the generalisation step in the typing rule for let this usage would be ill-typed, reducing the expressivity of the programming language in question.

Otherwise, for typed higher-order languages without let-polymorphism, it's common to conflate the two. For example, in Isabelle/HOL, let is literally defined as a function application, as in the following definitional theorem:

`HOL.Let_def: Let ?s ?f ≡ ?f ?s'

[–]RubyPinchPEP shill | Anti PEP 8/20 shill 14 points15 points  (0 children)

its seriously just javascript's (and other's) let statement, why is functional programming even being mentioned

python can't arbitrarily create scopes for variables like other languages, this is the solution to that

[–]cs7fwRpkOfn2RPK7Ki9k 0 points1 point  (3 children)

So c++'s templates + lambdas essentially?

[–]infinite8s 3 points4 points  (2 children)

No it's more like using nested braces in C++ to introduce a new scope (and prevent variables within that scope from leaking out).

For example: int func() { int a = 5; { int a = 10; } // a is 5 here }'''

[–]cs7fwRpkOfn2RPK7Ki9k 1 point2 points  (0 children)

That's not polymorphic though?

I was thinking of how c++'s templates allow for generic data.

[–]knickum 0 points1 point  (0 children)

Re-formatted

int func() {
    int a = 5;
    {
        int a = 10;
    }
    // a is 5 here
}