#light open System.Runtime.InteropServices [<ProgId("cbFSharp.Demo")>] [<ComVisible(true)>] type Calculator() = let fibs = Seq.unfold (fun (n0, n1) -> Some(n0, (n1, n0 + n1))) (1,1) member x.firstN (x:int) = Seq.take x fibs |> Seq.to_arrayTo create the COM and register you would do like this (output should be similar but not exact):
C:\temp>md FSharpCOM C:\temp>cd FSharpCOM C:\temp\FSharpCOM>notepad FSharpCOM.fs C:\temp\FSharpCOM>sn -k cetin.snk Microsoft (R) .NET Framework Strong Name Utility Version 3.5.30729.1 Copyright (c) Microsoft Corporation. All rights reserved. Key pair written to cetin.snk C:\temp\FSharpCOM>"C:\Program Files\FSharp-1.9.6.2\bin\fsc.exe" -a --keyfile cetin.snk FSharpCOM.fs Microsoft F# Compiler, (c) Microsoft Corporation, All Rights Reserved F# Version 1.9.6.2, compiling for .NET Framework Version v2.0.50727 C:\temp\FSharpCOM>dir Volume in drive C is XPBoot Volume Serial Number is A8FA-725C Directory of C:\temp\FSharpCOM 02/16/2009 06:39 PM <DIR> . 02/16/2009 06:39 PM <DIR> .. 02/16/2009 06:38 PM 596 cetin.snk 02/16/2009 06:39 PM 5,632 FSharpCOM.dll 02/16/2009 06:38 PM 345 FSharpCOM.fs 3 File(s) 6,573 bytes 2 Dir(s) 64,522,588,160 bytes free C:\temp\FSharpCOM>regasm FSharpCOM.dll /codebase Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.3053 Copyright (C) Microsoft Corporation 1998-2004. All rights reserved. Types registered successfullyAnd finally test code in VFP:
clear o = Createobject('cbFSharp.Demo') Local Array laFib[1] laFib = o.FirstN(20) For ix = 1 To 20 ? laFib[m.ix] EndforPS: Fibonacci code is not mine, got from Robert Pickering's "Foundations of F#" book. The books are available via safari.