首页 文章

在F#中键入提供者和静态参数

提问于
浏览
3

我有一个库Library_1,它可以正确编译并定义提供的类型:

type modelforexcel =  FSharpx.ExcelFile<@"template.xls", "Brokernet", true>

当我将这个库包含在另一个项目Library_2中时,编译器会抱怨它在 new Library_2项目的根目录下找不到任何"Brokernet.template.xls" .

Error   4   'C:\Library_2\template.xls' could not be found. Check the spelling of the file name, and verify that the file location is correct.

我希望该类型引用原始的“Brokernet.template.xls”,所以我试图提供它的完整路径,但

type modelforexcel =  
   FSharpx.ExcelFile<__SOURCE_DIRECTORY__+@"Brokernet.template.xls", "Brokernet", true>

不起作用,因为我猜它不是文字(?)但是“显然”定义这个文字也不起作用

[<Literal>]
let a = __SOURCE_DIRECTORY__+@"Brokernet.template.xls"

有没有办法定义这样的“动态文字”?

edit

有趣的是,如果我在第一个库中的模块中定义我的类型

module Load =
   [<Literal>]
   let a = @"Brokernet.template.xls"
   type modelforexcel =  FSharpx.ExcelFile< a , "Brokernet", true>

然后,在第二个库中使用第一个库时,类型不会“重新生成”,类型提供程序不会抱怨文件缺少第二个库的根 .

这为F#的编译模型带来了深刻的见解,这些模型可能是大师最好的曝光 . 我只是说,作为一个粗略的人,“代码在模块中”

PS:我想这是一个可以通过适当的分阶段编译解决的问题 .

1 回答

  • 4

    正如评论中所示,使用相对路径,例如 @"..\Library_1\Brokernet.template.xls" 解决了这个问题 .

相关问题