Function templates in F#

后端 未结 4 784
我寻月下人不归
我寻月下人不归 2021-01-03 10:52

Let\'s say I am solving a particular problem and come up with a function

let function parameter1 ... = 
     a lot of adding, multiplying & so on with a         


        
4条回答
  •  余生分开走
    2021-01-03 11:20

    Here's an article on generic, numeric calculations in F#. In general, you have two options:

    • Static member constraints
    • Global numeric associations (available in F# PowerPack)

    ...or you can combine these techniques.

    In your case, it sounds like static constraints will work.

    A simple example from that article:

    let inline halfSquare num =
       let res = LanguagePrimitives.DivideByInt num 2
       res * res
    

提交回复
热议问题