.netf#naming-conventions

F# naming convention


Is there an "official" naming / casing convention for F#?

I'm always in doubt of using C# style or not:

Class.MyFunctionName or Module.my_function_name

In F# you're meant to mix BCL classes and F# library ones: they have different casing and the code looks very ugly.


Solution

  • Yes, there is confusion, because F# has morphed from OCaml to .Net over the years. Basically, the naming conventions are a "breaking change" - old code is inconsistent with new code.

    However, the May 2009 CTP has settled the issue.

    The Release Notes say...

    Standard Library Naming Conventions

    The naming conventions adopted for the F# library are as follows:

    • All .NET and F# OO code uses PascalCase according to existing .NET guidelines

    • The F# functional programming operators such as List.map are for use in F# internal implementation code. This kind of code uses camelCase for operator names

    • Underscores should not be used.

    So, your question...

    Class.MyFunctionName or Module.my_function_name 
    

    The answer is

    Class.MyFunctionName and Module.MyFunctionName (but see edit below!)

    (applying rule 1 above).

    -- Edit. Nov 2, 2019 --

    The current guidelines recommend camelCase for functions at module level, so it's

    Module.myFunctionName

    Which then makes production code consistent with the F# libraries (eg. List.averageBy)