While I definitely author fewer classes in F# compared to C#, I do still use classes a bit. The main advantages for classes I see offhand are:

Sometimes an object with mutable state and an encapsulated abstraction just feels like the best way to model something, in which case classes are a great fit.

Members are often more discoverable than let-bound functions in modules, thanks to Intellisense and 'dotting into' objects. (Admittedly you can put members on DUs and record types as well as on classes.)

If you want to create a library API that is usable from other languages (like C#), the namespaces and classes are definitely the right way to expose a familiar and interoperable API.

Classes do interfaces and inheritance. Though I use these more rarely from F#, it is still good to have them when you need them.

But different people may have different opinions on this topic.

By on 11/24/2010 1:20 PM ()

I'm interested in build an AI system, it's about knowledge.

There's a base class names Descriptor with properties Name and Description, and now I want to make a derived class names Machine with a new property Parts. Is there another way in F# makes equivalent result?

I searched about "inherit" in the reference and it says only classes can be inherited.

By on 11/24/2010 1:19 PM ()

In addition to inheritance, there's always delegation; this is true in pretty much any OO language. You can do Machine is-a Descriptor via inheritance, or Machine has-a Descriptor by having it contain it as an instance member. Those are the two main mechanisms for such reuse.

By on 11/24/2010 1:23 PM ()

So, as I considered, in F# I'm always talking with a main module -- the system/environment/only controller. And only modules contains logic, all others (as I previously learned in C#: classes) should be just records/data controlling/computing by specified modules, is it correct?

By on 11/24/2010 3:50 PM ()

Thanks Brian, you have made good answer to my question, so let me built it on the second opinion, keep trying to work in another way during programing with F#.

By on 11/24/2010 1:35 PM ()

Maybe use classes is better fit for modeling, but I'll keep more trying with records and member referencing until I ensure to change to uss classes is required.

By on 11/24/2010 2:00 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