How to use attributes in F # interface?

I would like to define one of my parameters as a C # out parameter in one of my interfaces. I understand that F # supports byref , but how can I apply System.Runtime.InteropServices.OutAttribute to one of the interface parameters?

C # interface I'm trying to replicate

 public interface IStatisticalTests { void JohansenWrapper( double[,] dat, double alpha, bool doAdfPreTests, out double cointStatus, out JohansenModelParameters[] johansenModelParameters); } 
+7
f #
source share
1 answer

Here is an example:

 open System open System.Runtime.InteropServices [<Interface>] type IPrimitiveParser = // abstract TryParseInt32 : str:string * [<Out>] value:byref<int> -> bool [<EntryPoint>] let main argv = let parser = { new IPrimitiveParser with member __.TryParseInt32 (str, value) = let success, v = System.Int32.TryParse str if success then value <- v success } match parser.TryParseInt32 "123" with | true, value -> printfn "The parsed value is %i." value | false, _ -> printfn "The string could not be parsed." 0 // Success 

Here is your interface translated:

 [<Interface>] type IStatisticalTests = // abstract JohansenWrapper : dat:float[,] * alpha:float * doAdfPreTests:bool * [<Out>] cointStatus:byref<float> * [<Out>] johansenModelParameters:byref<JohansenModelParameters[]> -> unit 
+11
source share

All Articles