in expert fshap 2.0 page 133

open System.Drawing

type LabelInfo(?text:string, ?font:Font) =

let text = defaultArg text ""

let font = match font with

| None -> new Font(FontFamily.GenericSansSerif,12.0f)

| Some v -> v

member x.Text = text

member x.Font = font

"■ Note The second argument given to the defaultArg function is evaluated before the function is called. This

means you should take care that this argument isn’t expensive to compute and doesn’t need to be disposed. The

previous example uses a match expression to specify the default for the font argument for this reason."

"The second argument given to the defaultArg function is evaluated before the function is called. " i can not sume what author means, and is the first argument evaluated before the function called too?

Thank you so much for sharing.

__________________
Watch Resident Evil: Afterlife Online Free

By on 9/8/2010 8:53 PM ()

Sometimes people get wrong impression about defaultArg function: they expect second argument to be evaluated only if first one is None. This assumption is incorrect since F# is not lazy language and both arguments are computed even if value of first argument exists.

By on 9/7/2010 10:27 PM ()

thank you !!

By on 9/8/2010 6:20 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper