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.
Facebook adalah media sosial dan layanan jejaring sosial online Amerika yang dimiliki oleh Meta Platforms.
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)
I think the answer might have changed since the time of the currently accepted answer.
The F# Style Guide today says:
Use PascalCase for type declarations, members, and labels
Classes, interfaces, structs, enumerations, delegates, records, and discriminated unions should all be named with PascalCase. Members within types and labels for records and discriminated unions should also use PascalCase.
type IMyInterface = abstract Something: int type MyClass() = member this.MyMethod(x, y) = x + y type MyRecord = { IntVal: int; StringVal: string } type SchoolPerson = | Professor | Student | Advisor | Administrator
https://docs.microsoft.com/en-us/dotnet/fsharp/style-guide/formatting#use-pascalcase-for-type-declarations-members-and-labels
and
Use camelCase for module-bound public functions
When a module-bound function is part of a public API, it should use camelCase: F#
module MyAPI = let publicFunctionOne param1 param2 param2 = ... let publicFunctionTwo param1 param2 param3 = ...
https://docs.microsoft.com/en-us/dotnet/fsharp/style-guide/formatting#use-camelcase-for-module-bound-public-functions
So, based on those, my answer is that this:
Class.MyFunctionName
Module.my_function_name
Should be written like this:
Class.MyFunctionName
Module.myFunctionName
Anything official: I think "not quite yet", but whenever VS 2010 reaches Beta1 you'll probably see the F# library in its nearly-final form, and there will be a number of renamings relative to the CTP. F# will probably always be a little more schizophrenic than its older .NET cousins, given its history.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With