相同类型的冲突版本

时间:2016-07-15 15:12:38

标签: f# f#-interactive

我有以下F#脚本文件:

common.fsx

type CommonRecord = { Name : string }

intMapper.fsx

#load "common.fsx"
open Common

let toInt payload = payload.Name.Length

stringMapper.fsx

#load "common.fsx"
open Common

let toString payload = payload.Name

caller.fsx

#load "stringMapper.fsx"
#load "intMapper.fsx"
open Common

let a = { Name = "Hello " }
let str : string = StringMapper.toString a
let i : int = IntMapper.toInt a

当我尝试在F#Interactive中运行caller.fsx时,我收到以下编译器错误:

caller.fsx(8,42): error FS0001: This expression was expected to have type
FSI_0037.Common.CommonRecord    
but here has type
FSI_0038.Common.CommonRecord 

我猜这是因为当我加载stringMapper.fsx和intMapper.fsx中的每一个时,我加载了common.fsx的不同实例,然后编译器就会混淆。

是否有推荐的方法来实现我想要做的事情?即我的脚本文件中的依赖树是不是“完全有序”?

解决方法

正如乍得所说 - 这是不可能做到的。我使用的工作是将我的通用脚本编译为dll:

fsc.exe --target:library Common.fsx

然后使用#r Common.dll在脚本中引用它。

0 个答案:

没有答案
相关问题