F# supports classes and methods alongside its functional features. Classes normally contain methods and can serve as a practical bridge to object-oriented .NET code, while modules and functions remain the idiomatic functional tools. section 6.1.6 section 11.1.1
Use a class when you need to:
- Create instances and call methods from existing C# or .NET libraries. section 11.1.1
- Represent data shared by several methods through a lightweight constructor and class definition. section 15.2.1
- Apply object-oriented composition, such as passing an interface implementation into a class. section 15.2.1
Consuming a C# class
After referencing a C# project, F# can construct and use its class directly: open CsCode let person = Person () printfn $"{person.Name} is {person.Age} years old!" F# also permits constructor-call syntax such as FileInfo path or new FileInfo(path); the former is presented as the more idiomatic form. section 11.1.1
Injecting behavior through an interface
A class can receive an IPrinter and delegate output to it. The same ATM logic can therefore print to the console, append to a file, or use another implementation without changing its customer-description method.
Table 6.1 Comparing functions and methods in F# (view table figure)
Compare classes and methods with modules and functions across placement, instance use, currying, overloading, type inference, optional arguments, and pipelines. section 6.1.6




















