Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to do function overloading in F#?

Something like

let f x = log(x)

and later I can apply f to matrix, vector or a float.

I guess it is not possible since F# is strictly static typed. Any other patters to overcome this problem?

Thanks!

like image 626
Yin Zhu Avatar asked Dec 20 '09 15:12

Yin Zhu


People also ask

Is function overloading is possible in C?

Function overloading is a feature of Object Oriented programming languages like Java and C++. As we know, C is not an Object Oriented programming language. Therefore, C does not support function overloading.

Can we have overloading of the function?

You may overload a function template either by a non-template function or by another function template. The function call f(1, 2) could match the argument types of both the template function and the non-template function.

Is overloading of a function possible in the same class?

Yes since it has the same name but with a different parameter type.

What are the conditions for function overloading?

As explained from the definition of Function Overloading in C++, to overload two or more functions, they must have the same function name and different parameters that are either a different number of parameters or different data types of parameters or both.


1 Answers

See my answer to this question:

Functions with generic parameter types

Briefly:

  • You can overload members of a class (but not let-bound functions)
  • You can use 'inline' and 'hat' types
  • You can simulate Haskell type classes and explicitly pass dictionaries-of-methods
  • You can use do run-time type tests casting from 'obj'
like image 94
Brian Avatar answered Sep 18 '22 00:09

Brian