开发者

Using assembly attributes in F#

I'm trying to translate the following C# example, which constructs an IronPython module, to F#.

using System;
using IronPython.Runtime;

[assembly: PythonModule("my_module", typeof开发者_如何学运维(MyModule))]

public static class MyModule {
    public static void hello_world() {
        Console.WriteLine("hello world");
    }
}

Using PythonModule allows from my_module import *, among other things.

I am having trouble figuring out how to apply the PythonModule attribute in F#. The F# documentation only talks about assembly attributes related to modules, and attached to do(). It's not clear to me how to define static classes that are interpreted as python modules, but I am not a C#/F#/IronPython expert.


I don't have all the bits at hand to see if this works, but I would try

open System
open IronPython.Runtime

type MyModule = 
    static member hello_world() =
        Console.WriteLine("hello world")

module DummyModuleOnWhichToAttachAssemblyAttribute =
    [<assembly: PythonModule("my_module", typeof<MyModule>)>] 
    do ()

for starters.


Haven't tested it but...

module MyModule 

open System
open IronPython.Runtime

let hello_world () =
    Console.WriteLine "Hello, World."

[<assembly: PythonModule("my_module", typeof<MyModule>)>] 
do ()

Same as Brian's, but without the dummy module.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜