As Reed mentioned, functions can be defined within a la modules of other ML languages, but they can also be defined on types such as other .NET languages (and in fact modules are also compiled for classes). Inside F #, modules can be open ed to access functions without having to use the module name each time, and modules are automatically created for each file if they are not explicitly declared.
As for the individual cos functions, etc. Instead of just relying on the built-in .NET Math.Cos , etc., there may be several reasons:
- Homogeneity:
cos looks much more idiomatic in F # than calling the static System.Math.Cos method. - Static restrictions:
cos works not only on float in F #, but also works on float32 and on any type that the static cos method provides, so you can create your own types, you can use the cos function.
I would suggest that truly free features are not allowed, because there are many .NET languages that do not provide convenient access to them, so using them can become an obstacle to cross-language compatibility. The CLR itself supports free functions, and some languages, such as C ++ / CLI, use them, but most languages compile functions into classes (even if this is not the way it looks from the point of view of the source code, as in F #).
source share