因为不得不问这个问题,我觉得自己像个总菜鸟,但这让我很难过.
我设置了这样的格式字符串:
let fs = "This is my format test %s"
Run Code Online (Sandbox Code Playgroud)
然后我试着像这样使用它:
let s = sprintf fs "testing"
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我收到此错误:
//stdin(26,17): error FS0001: The type 'string' is not compatible with the type 'Printf.StringFormat<('a -> 'b)>'
Run Code Online (Sandbox Code Playgroud)
所以我接着尝试了这个:
let s = sprintf (Printf.StringFormat fs) "test"
Run Code Online (Sandbox Code Playgroud)
REPL回复的内容:
//stdin(28,18): error FS1124: Multiple types exist called 'StringFormat', taking different numbers of generic parameters. Provide a type instantiation to disambiguate the type resolution, e.g. 'StringFormat<_>'.
Run Code Online (Sandbox Code Playgroud)
所以我接着尝试了这个:
let s = sprintf (Printf.StringFormat<string> fs) "test"
Run Code Online (Sandbox Code Playgroud)
我得到了这个:
//stdin(29,18): error FS0001: …Run Code Online (Sandbox Code Playgroud) 如何将字符串"Hello"拆分为字符列表,例如,如何将字符串拆分为F sharp中的字符列表.
"Hello" ->['H';'e';'l';'l';'o']
Run Code Online (Sandbox Code Playgroud)
我尝试过 Split([| |]),但它只根据你传入的参数拆分一个字符串.
我试过这个,但它仍然没有用
let splitChar (text:string) =
[for c in text ->c]
let splitChar (text:string) =
[for c in text do yield c]
Run Code Online (Sandbox Code Playgroud) F#Interactive(以及一般的REPL样式工具)是性能分析的理想入口.有什么比选择代码块并将其直接发送到将返回性能分析报告的分析器更容易的事情.不幸的是,现有的分析器看起来没有REPL支持:您必须将分析器附加到进程或指定可执行文件或Web应用程序以进行分析.
我最终要做的是将代码块包装到单元测试中的配置文件,然后针对NUnit命令行会话执行配置文件.但这是我们现在用F#做的最好的事情吗?
我正在为我的F#项目添加第三方dll引用.我在引用中添加了dll,当我使用它时,即突出显示代码并执行Alt + Ent,我得到错误"命名空间或模块'AZROLESLib'未定义." 我错过了一些东西.
免责声明: 总 F#新手问题!
如果我在Visual Studio中的F#文件中键入以下内容
#light
let squares =
seq { for x in 1 .. 10 -> x * x }
printf "%A" squares
Run Code Online (Sandbox Code Playgroud)
并通过突出显示并按Alt+ 运行F#interactive,Enter交互式窗口中的输出为
>
seq [1; 4; 9; 16; ...]
val squares : seq<int>
>
Run Code Online (Sandbox Code Playgroud)
但我希望看到完整的序列即
>
seq [1; 4; 9; 16; 25; 36; 49; 64; 81; 100]
val squares : seq<int>
>
Run Code Online (Sandbox Code Playgroud)
这可能吗?我希望有一个我错过的环境.
我想将F#用于我之前使用批处理文件的一些非常基本的任务.我可以将fsx文件与fsi.exe关联起来并通过双击它来运行它.到目前为止,这很棒.
但是,有时我可能想深入研究代码并进行调试.当我在Visual Studio中打开fsx文件时,我无法运行它,但我也无法选择行并使用"发送到交互式".
在我看来,如果你设置一个完整的F#项目,这些命令才有效.这似乎很麻烦(作为批处理文件替换).我想知道哪种方法正确?我想吃蛋糕然后吃!我想要一个简单的文件,我可以快速更改,但我也希望能够根据需要使用Visual Studio进行分析.
更新 我刚刚发现您可以在"View\Other Windows\F#Interactive"中打开交互式控制台,然后您可以使用"发送到交互式"命令.
我仍然缺乏运行代码和设置断点的能力,但..
如果使用F#Interactive Shell(FSI),则推断的表达式类型(签名)将与其值一起打印到控制台:
val it : int * string * float = (42, "Hello F#", 42.0)
Run Code Online (Sandbox Code Playgroud)
如何在我自己的代码中模仿相同的行为,例如将推断的类型作为F#表达式的字符串?
我不需要动态评估任何F#表达式,这些表达式在编译时是已知的,并且是我的(静态)F#代码的一部分.我需要这个功能才能在我的F#演示中模仿LINQPad中的FSI输出.
有点像F#初学者.我试图在交互式窗口中测试我的一些XmlTypeProvider代码,首先在脚本(fsx)文件中输入它.脚本文件将无法识别以下内容
open FSharp.Data // gives "The namespace or module 'FSharp' is not defined"
Run Code Online (Sandbox Code Playgroud)
所有内容都已添加到引用中,.fs文件似乎没有找到XmlTypeProvider引用的任何问题但由于某种原因,同一项目中的脚本没有.我甚至让代码在.fs文件中工作.
我用nuget添加了FSharp.Data,一切似乎都正确添加.我在这里错过了什么?
在F#interactive中,如何查看此会话中定义的变量/函数列表?像whos()python或ls()R中的函数一样?谢谢.
我使用F#作为FSI的脚本语言.有没有办法在我的脚本中包含另一个fsx文件?我希望能够将我的脚本分成多个文件以执行更大的任务.
谢谢.