F# 您能在F中列出名称空间或模块的内容吗#

F# 您能在F中列出名称空间或模块的内容吗#,f#,F#,类似于,是否可以在F#中列出命名空间或模块的内容?当我为加载的DLL打开名称空间时,我没有收到名称空间不存在的错误,但是当我尝试使用文档化函数时,我看到名称空间不存在的错误 我正在寻找一种列出值和方法而不依赖IDE的编程方式。例如,如果我加载了F#repl,我将查找类似的内容: > #r "mylib.DLL" > open MyLib.Math > list-namespace-content MyLib.Math;; val it : string = """

类似于,是否可以在F#中列出命名空间或模块的内容?当我为加载的DLL打开名称空间时,我没有收到名称空间不存在的错误,但是当我尝试使用文档化函数时,我看到名称空间不存在的错误

我正在寻找一种列出值和方法而不依赖IDE的编程方式。例如,如果我加载了F#repl,我将查找类似的内容:

> #r "mylib.DLL"
> open MyLib.Math
> list-namespace-content MyLib.Math;;
   val it : string = """
      MyLib.Math.Add : int -> int -> int
      MyLib.Math.TryDivide : int -> int -> int option
      MyLib.Math.Pi : float
   """

据我所知,没有这样的函数可以做到这一点(我浏览了一下模块),但您可以自己编写一个。所有的积木都在那里

尽管看起来很奇怪,名称空间并不是F#、C#和Visual Basic.NET都使用的.NET平台的一部分。在IL级别,类型只是名称空间,只是作为组成类型名称的字符串的第一部分出现

但是,给定程序集,可以列出其所有类型或其所有公共类型。下面是后者的一个例子,我最近写了一篇关于网球卡塔的F#assembly:

> open System.Reflection;;
> let a = Assembly.LoadFrom @"<path>\Ploeh.Katas.Tennis.PropertyBased.dll";;

val a : Assembly =
  Ploeh.Katas.Tennis.PropertyBased, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

> let ts = a.GetExportedTypes();;

val ts : System.Type [] =
  [|Ploeh.Katas.PropertyBased.TennisProperties;
    Ploeh.Katas.PropertyBased.Tennis; Ploeh.Katas.PropertyBased.Tennis+Player;
    Ploeh.Katas.PropertyBased.Tennis+Player+Tags;
    Ploeh.Katas.PropertyBased.Tennis+Point;
    Ploeh.Katas.PropertyBased.Tennis+Point+Tags;
    Ploeh.Katas.PropertyBased.Tennis+PointsData;
    Ploeh.Katas.PropertyBased.Tennis+FortyData;
    Ploeh.Katas.PropertyBased.Tennis+Score;
    Ploeh.Katas.PropertyBased.Tennis+Score+Tags;
    Ploeh.Katas.PropertyBased.Tennis+Score+Points;
    Ploeh.Katas.PropertyBased.Tennis+Score+Forty;
    Ploeh.Katas.PropertyBased.Tennis+Score+Advantage;
    Ploeh.Katas.PropertyBased.Tennis+Score+Game|]
如果您想列出
网球
模块中的所有功能,可以这样做:

> open Microsoft.FSharp.Core;;
> let modules =
    ts
    |> Array.filter
        (fun t -> t.GetCustomAttributes<CompilationMappingAttribute>()
                    |> Seq.exists (fun attr -> attr.SourceConstructFlags = SourceConstructFlags.Module));;

val modules : System.Type [] =
  [|Ploeh.Katas.PropertyBased.TennisProperties;
    Ploeh.Katas.PropertyBased.Tennis|]
> let tm = modules |> Array.find (fun t -> t.Name = "Tennis");;

val tm : System.Type = Ploeh.Katas.PropertyBased.Tennis

> let functions = tm.GetMethods ();;

val functions : MethodInfo [] =
  [|Player other(Player);
    Microsoft.FSharp.Core.FSharpOption`1[Ploeh.Katas.PropertyBased.Tennis+Point] incrementPoint(Point);
    Point pointFor(Player, PointsData);
    PointsData pointTo(Player, Point, PointsData);
    Score scorePoints(Player, PointsData); Score scoreForty(Player, FortyData);
    Score scoreDeuce(Player); Score scoreAdvantage(Player, Player);
    Score scoreGame(Player); Score score(Score, Player); Score get_newGame();
    Score scoreSeq(System.Collections.Generic.IEnumerable`1[Ploeh.Katas.PropertyBased.Tennis+Player]);
    System.String pointToString(Point);
    System.String scoreToString(System.String, System.String, Score);
    System.String ToString(); Boolean Equals(System.Object);
    Int32 GetHashCode(); System.Type GetType()|]

您可能希望过滤掉一些继承的方法,例如
ToString
GetHashCode

您能提供有关错误的更多详细信息吗?(在F#中,当您键入
List时,您可以看到模块中的所有函数,例如
List
在编辑器中使用F#绑定-尽管您也可以使用反射从代码中列出它们)我的编辑器没有F#绑定。我正在寻找在repl中加载dll的情况。如果通过
#load
加载源文件,您将看到名称空间/模块内容的打印输出。但是如果你引用了一个dll或者只是打开了一个名称空间,你就看不到内容了。只是出于好奇-你在用什么编辑器?其中很多都有F#支持,包括Emacs、vim、Atom、Sublime、Xamarin Studio(当然还有VS)。我使用vim,但我还没有发现任何与操作系统/语言无关的标签处理方法。我使用了很多不同的系统,但随身携带了我的vim配置,所以我不能确定在工作站上除了vim之外还有什么。我不是vim专家,但有一个软件包:(但我非常确定,你至少需要mono和一个可执行文件才能获得vim方面的丰富经验)。