You rarely need to use fun like that. Defining a function with normal arguments intead of a value that's a function works the same:

1
let MMddyyyy (tw:TextWriter) (date:DateTime) =  tw.Write(date.ToString("MMddyyyy"))

That's pretty concise as there's not many ways we can get inference to help out here. You could use Printf.twprintf:

1
let MMddyyyy tw (date:DateTime) = Printf.twprintf tw "%s" <| date.ToString("MMddyyyy")

But that is actually a few characters longer. Is there something in particular you're looking for?

By on 4/7/2009 8:00 PM ()
1
2
3
let MMddyyyy =

    (fun (tw:TextWriter) (date:DateTime) -> tw.Write(date.ToString("MMddyyyy")))
1
let MMddyyyy (tw:TextWriter) (date:DateTime) = tw.Write(date.ToString("MMddyyyy"))

Implied by his post: The first version returns a closure, which holds the function and its environment. The second version is simply a function.

I don't know if it makes that big of a difference for you in your particular case (and I don't think it will in most cases). But, since they are equivalent to use, cheaper seems to be better.

By on 4/7/2009 8:59 PM ()
1
let MMddyyyy =     (fun (tw:TextWriter) (date:DateTime) -> tw.Write(date.ToString("MMddyyyy")))
1
let MMddyyyy (tw:TextWriter) (date:DateTime) = tw.Write(date.ToString("MMddyyyy"))

Implied by his post: The first version returns a closure, which holds the function and its environment. The second version is simply a function. I don't know if it makes that big of a difference for you in your particular case (and I don't think it will in most cases). But, since they are equivalent to use, cheaper seems to be better.

How is it a closure? It doesn't capture any variables. They should be identical. They have the exact same type (compile with --sig to see the interface), and compile to the exact same code.

I think the only times it matters are:

- If it's actually a closure

- Value restriction

I might have missed some cases -- please let me know.

Members have other things to consider, as calling them syntactically adds some special things (named parameters, function to delegate, etc.)

By on 4/7/2009 9:20 PM ()

Oh, and if you want to use inline, you'll have to use a syntactic function. Inline values are currently deprecated and "rec inline" can crash FSC :).

By on 4/7/2009 9:26 PM ()

Sorry for responding so late. I feel as though I may not have explained myself clearly enough. I should specify, is there any more efficient way to code that and still use the "%a" syntax within the format string?

By on 4/12/2009 4:39 PM ()
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