Desugared Surrender Form

What does the let (x = 0) in x * xtranslation do? Function (fun x -> x * x) 0)? “That would make sense, because letbindings are expressions, and expressions should return values ​​(just like functions).”

Example:

let result1 = 
    (fun n1 -> (fun n2 -> 
    (fun n3 -> n1 + n2 + n3 ) 3) 2) 1

let result2 = 
    let n1 = 1 in
    let n2 = 2 in
    let n3 = 3 in
    n1 + n2 + n3

let result3 = 
    let n1 = 1
    let n2 = 2
    let n3 = 3
    n1 + n2 + n3

I have the right to assume that it result3is a pronounced form result2, but result2- a pronounced form result1?

Short: Do let inbindings translate into functions?

+4
source share
3 answers

You can almost see let x = e1 in e2as syntactic sugar for (fun x -> e2) e1.

: , , - ( , ), .

, , ML- ( F #) , let. , fun, . , let ( , ).

, let :

let id = (fun x -> x) in ignore(id 1); ignore(id "A")

, id :

(fun id -> ignore(id 1); ignore(id "A")) (fun x -> x)
+11

let - let … in.

MSDN: (F #):

let:

:

let f x =
    let a = 1
    let b = 2
    x + a + b

:

let f x =
    let a = 1 in
    let b = 2 in
    x + a + b

let . CIL:

f:
IL_0000:  nop         
IL_0001:  ldarg.0     
IL_0002:  ldc.i4.1    
IL_0003:  add         
IL_0004:  ldc.i4.2    
IL_0005:  add         
IL_0006:  ret 

, f. a b f.

+4

let x = <val> in <expr>functionally equivalent (fun x -> <expr>) <val>.

  • <expr> - expression
  • <val> - value

Keyword inis optional.

+1
source

All Articles