Functions with generic parameter types

前端 未结 5 1572
傲寒
傲寒 2020-11-27 02:38

I am trying to figure out how to define a function that works on multiple types of parameters (e.g. int and int64). As I understand it, function overloading is not possible

5条回答
  •  萌比男神i
    2020-11-27 03:35

    Not to take away from the correct answers already provided, but you can in fact use type constraints in pattern matching. The syntax is:

    | :? type ->
    

    Or if you want to combine type checking and casting:

    | :? type as foo ->
    

提交回复
热议问题