F# has several ways to encapsulate and package you code (as described in Chapter 7 of Expert F#). The main difference between namespaces and modules is that modules can contain values, such as functions. Both can contain types, such as class types. I had a bit of trouble with the understanding at first, coming from OO languages like Java and C#. Another basic question is: What is the difference between functions and methods? A method is a member function of a type, like class types. Methods, like other members, use PascalCase. Functions defined in modules, generally use camelCase.

I'm not sure I'm explaining things very well, so it may be better to looks at some F# code. I just committed some code yesterday, so lets review this:

[link:code.google.com]

I usually define a base namespace, say what modules and namespaces I'm opening, then define my module(s). Opening a module is sort of like doing a static import in Java. You get to use the values without qualifying them. If I would have opening Wif.Msi, to call the openDatabase function, I would have needed to say Msi.openDatabase. In that Wif.Gui module I'm created a basic WPF GUI via F#. I defined 4 functions at the module level, including on I named main(), which is the entry point for the application I'm building.

May be not the best example, but hopefully it helps.

Cameron

By on 10/17/2009 4:27 PM ()

Thanks, that's very helpful indeed. I'll also read Chapter 7 of the book again, it's been a while.

I think in your code, "dock" is a function, while "Covert" in "StringArrayConverter" is a method. Right?

Thanks.

By on 10/18/2009 2:09 AM ()

Yes, dock is a function that takes three parameters that are curried, rather than tupled. When I first started programming in F#, I kept defining functions with arguments in parenthesis separated by commas as tuples, since that was what I was used to. Methods are defined with tuppled parameters. When defining functions in F#, curried parameters is preferred.

StingArrayConverter is a class type, hence the keywork "type". The first line there is also defining the constructor for the class. The class implements the interface IValueConverter which requires two methods to be defined: Convert and ConvertBack. Notice that the parameters for those methods are tupled parameters.

By on 10/19/2009 10:45 AM ()

Thanks for the explanations!

By on 10/19/2009 1:16 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