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
我可以在F#Interactive中获得不带内容的值的推断类型吗?_F#_Fsi - Fatal编程技术网

我可以在F#Interactive中获得不带内容的值的推断类型吗?

我可以在F#Interactive中获得不带内容的值的推断类型吗?,f#,fsi,F#,Fsi,在F#交互式控制台中创建值时,将显示推断的值类型和内容 在以后的日子里,我如何在不显示所有内容的情况下重新显示推断的类型 例如,我有一个包含1000项的数组,mydata。在F#Interactive console中键入mydata将显示类型以及数组的内容。具有类型的扩展属性: > let mydata = [|Some([42])|];; val mydata : int list option [] = [|Some [42]|] > mydata.GetType().FSha

在F#交互式控制台中创建值时,将显示推断的值类型和内容

在以后的日子里,我如何在不显示所有内容的情况下重新显示推断的类型

例如,我有一个包含1000项的数组,
mydata
。在F#Interactive console中键入
mydata
将显示类型以及数组的内容。

具有类型的扩展属性:

> let mydata = [|Some([42])|];;
val mydata : int list option [] = [|Some [42]|]
> mydata.GetType().FSharpName;;
val it : string = "option<list<int>>[]"
>让mydata=[| Some([42])|];;
val mydata:int列表选项[]=[|一些[42]|]
>mydata.GetType().FSharpName;;
val it:string=“option[]”

将printfn与以下类型一起使用如何:

F# Interactive for F# 3.1 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License
For help type #help;;

> 
val mya : int [] = [|3; 2; 5; 6; 7; 8|]

> printfn "%A" (mya.GetType());;

System.Int32[]
val it : unit = ()
您可以使用一个小的实用功能来缩短所需的键入时间:

let pm v = printfn "%A" (v.GetType())
您可以按如下方式使用:

> pm mya;;

System.Int32[]
val it : unit = ()
“pm”代表“打印我”。随便你怎么称呼它:)

如果您不喜欢GetType()中的类型名,另一种方法就是在要计算的值中引起错误。这将为您提供一个更友好的F#type名称(当然,如果您不介意忽略错误的话)。例如,在列表中,您可以执行以下操作:

> 
val myl : string list = ["one"; "two"]

> printfn myl;;

Script.fsx(195,9): error FS0001: The type 'string list' is not compatible with the type 'Printf.TextWriterFormat<'a>'
>
val myl:string list=[“一”;“二”]
>printfn myl;;
Script.fsx(195,9):错误FS0001:类型“字符串列表”与类型“Printf.textWritePerformat”不兼容
fsi.ShowDeclarationValues <- false