James Parsons
James Parsons

Reputation: 6057

How to force a member function's argument to a specific type

I wrote a small F# library while messing around that contains a few math functions like the following:

namespace MyLib

type Math() =
    member this.add(a,b) =
        a+b

Now, I am trying to call it from C# like:

using System;
using MyLib;

class Test {
   static void main(string[] args) {
      Double sum = MyLib.add(1.2, 3.5)
      Console.WriteLine(sum.ToString());
   }
}

This code gives me an error, When I look at the function's signature, I see that it accepts two integers.

The reason I am using Doubles is because in another function, I am using F# exponentiation. How can I tell an F# function that it should accept Doubles as apposed to ints

Upvotes: 0

Views: 99

Answers (1)

Fyodor Soikin
Fyodor Soikin

Reputation: 80744

You can just add a type annotation explicitly:

type Math() =
    member this.add(a:float,b:float) =
        a+b

(note that System.Double is called float in F#)

Upvotes: 2

Related Questions