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.
Assembly attributes are values that provide information about an assembly. The attributes are divided into the following sets of information: Assembly identity attributes. Informational attributes. Assembly manifest attributes.
Assemblies form the fundamental units of deployment, version control, reuse, activation scoping, and security permissions for . NET-based applications. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality.
Assembly identity attributes Three attributes (with a strong name, if applicable) determine the identity of an assembly: name, version, and culture. These attributes form the full name of the assembly and are required when you reference it in code. You can set an assembly's version and culture using attributes.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With