F # File Files - Defining Designer Parameters

I am having an error creating a signature file for an F # script file that I cannot solve.

To replicate, create a new F # class library and add the Test.fs file:

namespace Signatures open System type Test (id : Guid, name : string) = member this.Id = id member this.Name = name 

It will be wonderful. Then create a new signature file above it, Test.fsi:

 namespace Signatures open System type Test = new : (Guid * String) -> Test member Id : Guid member Name : String 

Now it will not be built with the error Module 'Signatures' requires a value 'new : (Guid * String) -> Test (this is different from the error you get if the two files have a constructor signature). The only real documentation that I can find when defining constructors in a signature file is MSDN and refers to constructors without parameters.

If you hover over Test in the .fs file, then the signature of the constructor matches the signature in the .fsi file. I also tried changing the constructor so that it was not implicit without joy.

I am using VS2012 RC and have tried .Net 4 and 4.5.

+4
source share
3 answers

This is too long for a comment, so I am posting it as an answer.

Constructor

Test receives two arguments as its parameters, and not one argument, which is a tuple. I admit that * between arguments seems confusing. But the signature of Guid -> string -> Test even worse. Constructors must receive some inputs and instantiate a new type. Fuzzy form and partial application do not make sense in the context of constructors.

I think the brackets help clarify here.

 type Test (id : System.Guid, name : string) = member this.Id = id member this.Name = name 

creates new : id:Guid * name:string -> Test , and

 type Test (tuple: System.Guid * string) = let id, name = tuple member this.Id = id member this.Name = name 

gives me new : tuple:(Guid * string) -> Test in an FSI session. I am using F # 2.0 / MonoDevelop 3.0 for writing.

Regarding the creation of type signatures, I usually send the code to F # Interactive and copy the received signatures to fsi files to avoid errors. If the tooltips and F # Interactive display signature signatures on the VS2012 RC, you should report this in the fsbugs (at) microsoft (dot) com file.

+6
source

An extra pair of pares can be significant. Consider the following:

 type T = static member Add(x, y) = x + y static member AddTuple((x, y)) = x + y 

which in C # is displayed as

 int Add(int x, int y) int AddTuple(Tuple<int, int> arg) 

Tangentially, you cannot do something like this in the constructor:

 type Test((id, name)) = class end //DOESN'T COMPILE 

Since the constructors are already accepting arguments in the form, you might expect 'a * 'b and ('a * 'b) be different. This is consistent with the syntax of the method.

+3
source

If someone wants to explain why this works, I would love to know, but I just started playing with the syntax to see if I could get something more revealing from the compiler.

If I remove the brackets, this is a tuple, it compiles, i.e. changes this:

 new : (Guid * String) -> Test 

To:

 new : Guid * String -> Test 
+1
source

All Articles