I would like to implement the following C# interface in F#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mono.Addins;
[TypeExtensionPoint]
public interface ISparqlCommand
{
string Name { get; }
object Run(Dictionary<string, string> NamespacesDictionary, org.openrdf.repository.Repository repository, params object[] argsRest);
}
This is what I have tried, but it gives me: "Incomplete structured construct at or before this point in expression"
#light
module Module1
open System
open System.Collections.Generic;
type MyClass() =
interface ISparqlCommand with
member this.Name =
"Finding the path between two tops in the Graph"
member this.Run(NamespacesDictionary, repository, argsRest) =
new System.Object
What am I doing wrong? Maybe indentation is wrong?
The origin of C is closely tied to the development of the Unix operating system, originally implemented in assembly language on a PDP-7 by Dennis Ritchie and Ken Thompson, incorporating several ideas from colleagues. Eventually, they decided to port the operating system to a PDP-11.
Basically, an implementation is the combination of a compiler and the C library it supports. – Jonathan Leffler. Apr 15, 2019 at 14:20. 4. C language = what you type into a text editor; implementation = the thing that actually does something with what you typed.
I verified @Mark's answer in the comments. Given the following C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace org.openrdf.repository {
public class Repository {
}
}
namespace CSLib
{
[System.AttributeUsage(System.AttributeTargets.Interface)]
public class TypeExtensionPoint : System.Attribute
{
public TypeExtensionPoint()
{
}
}
[TypeExtensionPoint]
public interface ISparqlCommand
{
string Name { get; }
object Run(Dictionary<string, string> NamespacesDictionary, org.openrdf.repository.Repository repository, params object[] argsRest);
}
}
The following F# implementation (only change is adding ()
at the object construction) works "fine":
#light
module Module1
open System
open System.Collections.Generic;
open CSLib
type MyClass() =
interface ISparqlCommand with
member this.Name =
"Finding the path between two tops in the Graph"
member this.Run(NamespacesDictionary, repository, argsRest) =
new System.Object()
Though you don't need to use #light
anymore (it is the default) and you may want to head the NamespaceDictionary
paramater name warning that "Uppercase variable identifiers should not generally be used in patterns, and may indicate a misspelt pattern name." Also note that you will need to cast MyClass
to ISparqlCommand
in order to access the implemented members (not a question you asked, but easy to get confused by coming from C#): e.g (MyClass() :> ISparqlCommand).Name
Thanks to everyone! The following code actually works:
namespace MyNamespace
open System
open System.Collections.Generic;
open Mono.Addins
[<assembly:Addin>]
do()
[<assembly:AddinDependency("TextEditor", "1.0")>]
do()
[<Extension>]
type MyClass() =
interface ISparqlCommand with
member this.Name
with get() =
"Finding the path between two tops in a Graph"
member this.Run(NamespacesDictionary, repository, argsRest) =
new System.Object()
It is also an example of how to use Mono.Addins with F#
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