Function templates in F#

后端 未结 4 776
我寻月下人不归
我寻月下人不归 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:10

    One way to do it is combining inline keyword and generic bits from LanguagePrimitives module:

    let inline greatFunction param1 param2 = 
        let one = LanguagePrimitives.GenericOne
        let two = one + one
        (param1+one)/(param2*two)
    
    // Usage
    let f1 = greatFunction 4 2
    let f2 = greatFunction 4L 2L
    let f3 = greatFunction 4I 2I
    

提交回复
热议问题