zoukankan      html  css  js  c++  java
  • F#值语意

    // The following code demonstrates the use of reference
    // cells to enable partially applied arguments to be changed
    // by later code.
    
    let increment1 delta number = number + delta
    
    let mutable myMutableIncrement = 10
    
    // Closures created by partial application and literals.
    let incrementBy1 = increment1 1
    let incrementBy2 = increment1 2
    
    // Partial application of one argument from a mutable variable.
    let incrementMutable = increment1 myMutableIncrement
    
    myMutableIncrement <- 12
    
    // This line prints 110.
    printfn "%d" (incrementMutable 100)
    
    let myRefIncrement = ref 10
    
    // Partial application of one argument, dereferenced
    // from a reference cell.
    let incrementRef = increment1 !myRefIncrement
    
    myRefIncrement := 12
    
    // This line also prints 110.
    printfn "%d" (incrementRef 100)
    
    // Reset the value of the reference cell.
    myRefIncrement := 10
    
    // New increment function takes a reference cell.
    let increment2 delta number = number + !delta
    
    // Partial application of one argument, passing a reference cell
    // without dereferencing first.
    let incrementRef2 = increment2 myRefIncrement
    
    myRefIncrement := 12
    
    // This line prints 112.
    printfn "%d" (incrementRef2 100)
    
    
    
    -----------------
    let mutable x =1
    let x' =x
    x<-2
    x' (还是1,它拷贝了x的副本,因此不会被x的改变而改变s)
  • 相关阅读:
    内网横向渗透之票据传递攻击
    内网横向渗透之哈希传递攻击
    冰蝎2,3及哥斯拉特征分析
    钓鱼攻击之远程加载恶意Word模版文件上线CS
    powershell基础知识
    初学文件钓鱼
    powershell免杀
    tips
    ShardingSphere你还不会吗?(第一篇)
    Ubunt14.04+Nvidia drivers+cuda 8.0
  • 原文地址:https://www.cnblogs.com/jiangzhen/p/fsharp_value_semantics.html
Copyright © 2011-2022 走看看