Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using assembly attributes in F#

Tags:

c#

ironpython

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.

like image 708
Tristan Avatar asked Feb 15 '10 23:02

Tristan


People also ask

What are assembly attributes?

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.

What role does assemblies play in .NET environment?

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.

What are the attributes of Assemblyinfo CS file?

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.


Video Answer


2 Answers

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.

like image 107
Brian Avatar answered Sep 29 '22 05:09

Brian


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.

like image 31
pblasucci Avatar answered Sep 29 '22 07:09

pblasucci