Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用System.Collections.Immutable with F#和Mono_F#_Mono_Xamarin_.net 4.5_Immutability - Fatal编程技术网

使用System.Collections.Immutable with F#和Mono

使用System.Collections.Immutable with F#和Mono,f#,mono,xamarin,.net-4.5,immutability,F#,Mono,Xamarin,.net 4.5,Immutability,我试图使用Mono在F#中使用ImmutableDictionary。我正在使用Xamarin IDE 我已经将目标框架设置为Mono/.Net4.5,并使用内置的Nuget包管理器导入了System.Collections.Immutable 下一行 开放系统.集合.不可变 正在生成以下两个错误 '/Users/UserName/Projects/Xamarin/OrderInference/OrderInference/MyTest.fs(34,34):错误FS1109:在程序集“Syste

我试图使用Mono在F#中使用ImmutableDictionary。我正在使用Xamarin IDE

我已经将目标框架设置为Mono/.Net4.5,并使用内置的Nuget包管理器导入了System.Collections.Immutable

下一行

开放系统.集合.不可变

正在生成以下两个错误

'/Users/UserName/Projects/Xamarin/OrderInference/OrderInference/MyTest.fs(34,34):错误FS1109:在程序集“System.Runtime”中找到了对类型“System.Collections.Generic.IEnumerable”的引用,但在该程序集中找不到该类型(FS1109)(MyTest)

/Users/UserName/Projects/Xamarin/OrderInference/OrderInference:错误FS1108:此处需要类型“Lazy”2,但该类型不可用。必须添加对程序集“System.ComponentModel.Composition,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”的引用。(FS1108)(订单推理)

第二个错误建议我需要引用System.ComponentModel.Composition。我能用单声道吗?如果是,是否需要引用另一个程序集

编辑:
已删除解决方案并在下面作为答案重新发布

ImmutableDictionary是抽象的,因此
新建
将不起作用。但是,它确实提供了一些解决方案

ImmutableDictionary.Create()

可以通过添加对“System.ComponentModel.Composition”的引用来解决此问题。在Xamarin的IDE中,这是通过使用“编辑引用”对话框完成的,该对话框可以通过右键单击项目中的引用找到。转到所有选项卡并搜索
System.ComponentModel
,只需添加
System.ComponentModel.component
程序集即可

我现在安装了以下两个组件:

System.Collections.Immutable.dll
System.ComponentModel.Composition.dll
我的代码现在是:

open System
open System.ComponentModel.Composition
open System.Collections.Immutable

type wordPairs = { pairs:ImmutableDictionary<string, string>; count:int} 
let myPairs = {pairs = ImmutableDictionary.Create<string, string>(); count = 0}
开放系统
开放系统.ComponentModel.Composition
open System.Collections.Immutable
类型wordPairs={pairs:ImmutableDictionary;count:int}
让myPairs={pairs=ImmutableDictionary.Create();count=0}

注意:正如gradbot所指出的(Immo Landwerth后来挑剔了;>>),
ImmutableDictionary
是一个抽象的密封类。因此,它没有公共构造函数。因此,您需要使用
.Create
方法

根据第二个示例,至少应该部分正常。我可以通过“编辑引用”对话框手动添加System.ComponentModel程序集来消除这两个错误。
开放系统.Collections.Immutable
不再生成错误。但是,我仍然从“new ImmutableDictionary”行中得到一个
类型未定义的错误。他正在类型注释中使用它。我在任何地方都看不到新的。所以它应该有用。谢谢。虽然我没有新的
new
方法,但在下面的
wordPairs=ImmutableDictionary.Create()
行中添加一个就足以解决这个问题。吹毛求疵:
ImmutableDictionary
不是抽象的(它实际上是密封的)。只是我们没有提供任何公共构造师。这个Immo家伙是谁来挑剔的?他以为他是谁?这个集会的创造者?。。。哦,等等…@ImmoLandwerth哦,我刚刚在网络文档上看到[]并假设。典型的程序员错误。另一个挑剔:被密封并不意味着没有公共构造函数:-)
open System
open System.ComponentModel.Composition
open System.Collections.Immutable

type wordPairs = { pairs:ImmutableDictionary<string, string>; count:int} 
let myPairs = {pairs = ImmutableDictionary.Create<string, string>(); count = 0}