Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resolving overload ambiguity with null

Tags:

f#

I'm working with an API in F# (that I have no control over) which declares two constructors like so:

public TheType(string bar, bool foo)

public TheType(IDisposable baz, bool foo)

I need to create an instance of the object using the first constructor, but passing null for bar. The F# compiler of course gets confused about which constructor I am trying to resolve:

//Private field
static let blah : TheType = new TheType(null, false)

I can resolve the issue by casting null to string:

static let blah : TheType = new TheType(null :> string, false)

Which works, but that gives me a compilation warning:

The type 'string' does not have any proper subtypes and need not be used as the target of a static coercion

Which also makes sense. Is there a way to resolve the overload ambiguity without resorting to compilation warnings?

like image 241
vcsjones Avatar asked Mar 09 '14 17:03

vcsjones


1 Answers

You can specify the type of null:

static let blah : TheType = new TheType((null : string), false)
like image 126
Lee Avatar answered Sep 23 '22 08:09

Lee