Advertisement
Guest User

Optimization

a guest
May 31st, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.54 KB | None | 0 0
  1.  
  2. let times a b = a * b
  3.  
  4. let getFunc () =
  5.  
  6.   if random () > 0.5 then times 2 else times 3
  7.  
  8. let f = getFunc ()
  9.  
  10. // Compiler cannot inline f because the function is determined during runtime (currying creates new function)
  11. f 10 |> printfn "10*2 or 10*3 = %d"
  12.  
  13.  
  14.  
  15. type Times(a) =
  16.   member this.Invoke b = a * b
  17.  
  18. let getFunc () =
  19.   if random() > 0.5 then Times(2) else Times(3)
  20.  
  21. let f = getFunc ()
  22.  
  23. // Compiler can inline this because only data bound to f.this is determined during runtime
  24. f.Invoke 10 |> printfn "10*2 or 10*3 = %d"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement