>> Q1: Optional Arguments in C#
Yes, this is a limitation. Since C# doesn't support optional arguments there is unfortunately no way you could work with them as with optional arguments.

You could maybe use an alternative solution where the object has mutable members like this:

1
2
3
4
5
6
7
8
9
type Test() =
  let mutable n = 0
  let mutable s = ""
  member x.Num 
    with get() = n
    and set(v) = n<-v
  member x.String 
    with get() = s
    and set(v) = s<-v

This can be used from F# in a similar way as with optional arguments:

1
new Test(Num=42, String="Answer");;

From C# 2.0 you'll have to create an instance and set the poperties explicitly (which still may be more readable than using Option arguments), but from C# 3.0 it will be possible to use syntax similar to the one available in F#:

1
new Test { Num=42, String="Answer" };

>> Q2
Hmm, what is the type of "st"? If it's type inherited from SymbolTable<string> than you'll probably have to cast it to this type using "st :> SymbolTable<string>", however using ":?>" shouldn't be needed - this operator is a dynamic downcast (for casts that may fail - e.g. from "obj" to "SymbolTable<string>").

>> Q3: Constructors & overload resoluion
This is possible, but you'll have to do it explicitly:

1
2
3
4
5
type Test =
  [<OverloadID("ctor1")>]
  new (n:int) = { }
  [<OverloadID("ctor2")>]
  new (s:string) = { }

You might however consider other possible solutions - e.g. having a static methods to construct the object.

>> Q4
I can't really help with this one - looks like you have more unmanaged resources in your DLLs and the F# compiler can't merge them... What assemblies in your project contain an unmanaged resource? I think it should be possible to workaround this by removing the "--standalone" option (at least for debugging).

By on 7/30/2007 10:53 AM ()

Thanks a lot for the clean and quick reply;
about the Q2 and Q4 questions ...

Q2:
you have right: I have not explained well.
I had defined the following method in C#

1
public static string PreprocessSource(string src, SCLS.SymbolTable<string> st) 

from f# i must use

1
2
        static member preprocessing_rate_function_source((src:string), ( st : SymbolTable<string>)) : string = 
            SyntaxPreprocessor.PreprocessSource(src,(st :?> #SymbolTable<string>))

This compile and works but i got the following warnings:
- Warning: The instantiation of a generic construct at or near this point could not be resolved because it involves multiple unrelated types. Use type annotations to resolve the ambiguity.
- Warning: Couldn't determine a default assignment for an ungeneralized type variable.
- Warning FS0001: The type string SymbolTable is not compatible with the type string SymbolTable

with

1
2
        static member preprocessing_rate_function_source((src:string), ( st : SymbolTable<string>)) : string = 
            SyntaxPreprocessor.PreprocessSource(src,st )

they do not compile and I got
- Error : The type string SymbolTable is not compatible with the type string SymbolTable
- Error : Type constraint mismatch. The type string SymbolTable is not compatibile with type string SymbolTable . The type string SymbolTable is not compatible with the type string SymbolTable

with

1
2
        static member preprocessing_rate_function_source((src:string), ( st : SymbolTable<string>)) : string = 
            SyntaxPreprocessor.PreprocessSource(src, (st :>  SymbolTable<string>) )

they do not compile and I got the same 2 error of the last case
Q4:
The strange thing is that i don't use unmanaged resources; Naturally it work well without --standalone, but I am curious about the causes, because for distribute the project the --standalone it is very usefull.

Agains thanks and best regards
g.s.

By on 7/31/2007 3:10 AM ()

instead of :

1
2
3
4
//casts st to a SymbolTable<string>
static member preprocessing_rate_function_source((src:string), ( st : SymbolTable<string>)) : string = 
  //can't be upcast here since it is already defined as a SymbolTable<string>
  SyntaxPreprocessor.PreprocessSource(src, (st :>  SymbolTable<string>) )

The following might work

1
2
3
4
5
6
//define the argument type as something that can be cast to a SymbolTable<string>
static member preprocessing_rate_function_source((src:string), ( st : #SymbolTable<string>)) : string = 
  //cast it
  let st = st :> SymbolTable<string>
  // use it
  SyntaxPreprocessor.PreprocessSource(src, st)

You could leave both as

1
2
static member preprocessing_rate_function_source((src:string), ( st : SymbolTable<string>)) : string = 
  SyntaxPreprocessor.PreprocessSource(src, st)

and cast st when you need it in your code

By on 7/31/2007 5:05 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper