我在理解F#如何工作方面遇到了问题.我来自C#,我认为我正在努力使F#像C#一样工作.我最大的问题是以正确的格式返回值.
示例:假设我有一个带有整数和整数列表的函数.函数应该打印索引列表,其中列表匹配的值传递整数.
我的代码:
let indeks myList n = myList |> List.mapi (fun i x -> if x=n then i else 0);;
indeks [0..4] 3;;
Run Code Online (Sandbox Code Playgroud)
然而它返回:
val it : int list = [0; 0; 0; 3; 0]
Run Code Online (Sandbox Code Playgroud)
而不只是[3],因为我不能在该陈述中忽略其他.我还有 - > int list - > int - > int list的签名,我得到了别的东西.
同样的问题没有.2我想提供一个整数并打印从0到这个整数n次的每个数字(其中n是迭代值):示例:MultiplyValues 3 ;; 输出:[1; 2; 2; 3; 3; 3]
我能做的最好就是创建列表清单.
返回元素时我错过了什么?如何在返回
示例中不添加任何内容:if x = n then n else AddNothingToTheReturn
我在 VS2015 中安装了 NUnit 3.0,当我想生成新测试时,有两个选项:
- NUnit
- NUnit2
有什么不同?