F#中的打印顺序

时间:2009-08-18 14:25:55

标签: f#

我对F#很新,所以请原谅这个全新的问题:

我有一个存储在名为price的变量中的序列。我想将此序列的内容输出到交互式窗口。执行此操作的最简单命令是什么?

这是我的序列:

> prices;;
val it : seq<System.DateTime * float> = seq []

我已经尝试过printf'ing但是这给了我错误:

> printf("%A", prices);;

  printf("%A", prices);;
  -------^^^^^^^^^^^^

stdin(82,8): error FS0001: The type ''b * 'c' is not compatible with the type 'Printf.TextWriterFormat<'a>'

任何帮助都将不胜感激。

3 个答案:

答案 0 :(得分:16)

printf不带括号:

printfn "%A" prices;;

(详见F# function types: fun with tuples and currying

您也可以将seq转换为列表,例如

printfn "%A" (Seq.toList prices);;

答案 1 :(得分:3)

此外,您可以通过更改fsi。*属性来控制交互式会话打印机功能 (FloatingPointFormat,PrintWidth,PrintDepth,PrintLength,...) F.E.请参阅:http://cs.hubfs.net/forums/post/7438.aspx

答案 2 :(得分:2)

> prices;;
val it : seq<System.DateTime * float> = seq []

它正在完成它的工作:seq []表示序列为空。