Optional arguments certainly involve a trade-off because they have limitations (as you've noted) but they are often extremely useful. Specifically, you should not use them when the user is likely to want to compose them as functions as you have.

They are most useful when you have large numbers of arguments that have unsurprising default values and will be called directly, which often appears in init code and code intended for interactive use.

For example, F# for Visualization uses optional arguments in its Graph.Plot function so users can add more information when creating a graph plot without having to use (and remember) a multitude of incompatible functions. So you cannot use Graph.Plot in functional compositions but the trade-off is clearly in favor of optional arguments in that case.

By on 4/15/2008 9:23 PM ()

Hi all,

The first post in this thread is actually a place where we will make a design change in the next update release of F# (indeed we consider the behaviour described a bug).

When a method taking optional arguments is used as a first class value the optional arguments will no longer be part of the inferred type for the first class value and the optional arguments will have value "None" when the function is applied. This is much more consistent and regular.

Thanks

Don

By on 4/16/2008 4:13 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