(In learning from "Programming F# 3.0, 2nd Edition")
Define lazy instance
These two are completely same way.
> let current = lazy(System.DateTime.Now);;
val current : Lazy<System.DateTime> = Value is not created.
> let current = Lazy<System.DateTime>.Create(fun() -> System.DateTime.Now);;
val current : System.Lazy<System.DateTime> = Value is not created.
Evaluate lazy instance
These two are also completely same way.
> current.IsValueCreated;;
val it : bool = false
> current.Value;;
val it : System.DateTime = 2013/02/04 20:40:19 {Date = 2013/02/04 0:00:00;
Day = 4;
DayOfWeek = Monday;
DayOfYear = 35;
Hour = 20;
Kind = Local;
Millisecond = 676;
Minute = 40;
Month = 2;
Second = 19;
Ticks = 634956072196762680L;
TimeOfDay = 20:40:19.6762680;
Year = 2013;}
> current.IsValueCreated;;
val it : bool = true
> current.Value;;
val it : System.DateTime = 2013/02/04 20:40:19 {Date = 2013/02/04 0:00:00;
Day = 4;
DayOfWeek = Monday;
DayOfYear = 35;
Hour = 20;
Kind = Local;
Millisecond = 676;
Minute = 40;
Month = 2;
Second = 19;
Ticks = 634956072196762680L;
TimeOfDay = 20:40:19.6762680;
Year = 2013;}
> current.IsValueCreated;;
val it : bool = false
> current.Force();;
val it : System.DateTime = 2013/02/04 20:40:19 {Date = 2013/02/04 0:00:00;
Day = 4;
DayOfWeek = Monday;
DayOfYear = 35;
Hour = 20;
Kind = Local;
Millisecond = 676;
Minute = 40;
Month = 2;
Second = 19;
Ticks = 634956072196762680L;
TimeOfDay = 20:40:19.6762680;
Year = 2013;}
> current.IsValueCreated;;
val it : bool = true
> current.Force();;
val it : System.DateTime = 2013/02/04 20:40:19 {Date = 2013/02/04 0:00:00;
Day = 4;
DayOfWeek = Monday;
DayOfYear = 35;
Hour = 20;
Kind = Local;
Millisecond = 676;
Minute = 40;
Month = 2;
Second = 19;
Ticks = 634956072196762680L;
TimeOfDay = 20:40:19.6762680;
Year = 2013;}
No comments:
Post a Comment