0 people like it.

Evaluation Strategies

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
44: 
45: 
46: 
47: 
48: 
49: 
50: 
51: 
52: 
53: 
54: 
55: 
56: 
57: 
58: 
59: 
60: 
61: 
62: 
63: 
64: 
65: 
66: 
67: 
68: 
69: 
70: 
71: 
72: 
73: 
74: 
75: 
76: 
77: 
78: 
79: 
80: 
81: 
82: 
83: 
84: 
85: 
86: 
87: 
88: 
// A method with a “normal” (call-by-value) argument is declared like this 
(*
def foo(x: Int) = {
    val a = x
    val b = x
    (a, b)
}
foo({println("hello"); 2 + 2})

//hello
//res0: (Int, Int) = (4,4)
*)

let foo (x : int) =
    let a = x
    let b = x
    a, b
foo (printfn "Hello"; 2 + 2)
//Hello
//val it : int * int = (4, 4)

// A method with a lazy (call-by-name) argument is declared like this 
(*
def foo(x: => Int) = {
    val a = x
    val b = x
    (a, b)
}
foo({println("hello"); 2 + 2})

//hello
//hello
//res0: (Int, Int) = (4,4)
*)

let foo (x : unit -> int) =
    let a = x()
    let b = x()
    a, b
foo <| fun () -> printfn "hello"; 2 + 2
//hello
//hello
//val it : int * int = (4, 4)

// A method that takes a no-argument function (a thunk) is declared like this 
(*
def foo(x:() => Int) = {
    val a = x
    val b = x
    val c = x()
    (a, b, c)
}
foo(() => {println("hello"); 2 + 2})

//hello
//res0: (() => Int, () => Int, Int) = (<function>,<function>,4)

*)

let foo (x : unit -> int) =
    let a = x
    let b = x
    let c = x()
    a, b, c
foo <| fun () -> printfn "hello"; 2 + 2
//hello
//val it : (unit -> int) * (unit -> int) * int =
//  (<fun:it@65-10>, <fun:it@65-10>, 4)

// Lazy values allow you to turn call-by-name lazy arguments into call-by-need lazy arguments. 
(*
//def foo(def x: Int) = {
def foo(x: => Int) = {
    lazy val a = x
    (a, a, a)
}
foo({println("hello"); 2 + 2})

hello
res0: (Int, Int, Int) = (4,4,4)
*)

let foo (x : Lazy<int>) =
    let a = x
    a.Value, a.Value, a.Value
foo <| lazy (printfn "hello"; 2 + 2)
//hello
//val it : int * int * int = (4, 4, 4)
val foo : x:int -> int * int

Full name: Script.foo
val x : int
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
val a : int
val b : int
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
val foo : x:(unit -> int) -> int * int

Full name: Script.foo
val x : (unit -> int)
type unit = Unit

Full name: Microsoft.FSharp.Core.unit
val foo : x:(unit -> int) -> (unit -> int) * (unit -> int) * int

Full name: Script.foo
val a : (unit -> int)
val b : (unit -> int)
val c : int
val foo : x:Lazy<int> -> int * int * int

Full name: Script.foo
val x : Lazy<int>
Multiple items
active recognizer Lazy: Lazy<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.( |Lazy| )

--------------------
type Lazy<'T> = System.Lazy<'T>

Full name: Microsoft.FSharp.Control.Lazy<_>
val a : Lazy<int>
property System.Lazy.Value: int
Raw view Test code New version

More information

Link:http://fssnip.net/3W
Posted:14 years ago
Author:
Tags: