如何在我自己的代码中生成类似于 FSI 的 F# 类型签名? [英] How to generate the F# type signature similar to FSI in my own code?

查看:20
本文介绍了如何在我自己的代码中生成类似于 FSI 的 F# 类型签名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果使用 F# Interactive Shell (FSI),则推断的表达式类型 (.

使用 FsEye

另一种巧妙的方法是使用 LINQPad 的测试版 Custom Visualizer API 来嵌入 FsEye 到 LINQPad(FsEye 使用与 Unquote 相同的 F# 类型签名打印算法).这个也很简单,只需要下载LINQPad beta,下载参考FsEye.dll 来自最新版本的 FsEye,然后你可以做例如

If one uses the F# Interactive Shell (FSI), the inferred expression type (signature) is printed to the console along with its value:

val it : int * string * float = (42, "Hello F#", 42.0)

How can I mimick the same behaviour in my own code, e.g. to get the inferred types as string for a F# expression?

I don't need to dynamically evaluate any F# expressions, the expressions are known in compile time and are part of my (static) F# code. I need this feature to be able to mimick the FSI output in LINQPad for my F# demos.

解决方案

Using Unquote

Unquote has a facility for getting the F# signature of a type. Simply download the latest release and add a reference through LINQPad to Unquote.dll, then you can do e.g.

If you're interested, you can peak at the source code for the implementation of the FSharpName Type extension: http://code.google.com/p/unquote/source/browse/tags/2.1.0/Unquote/ExtraReflection.fs#54.

Using FsEye

Another neat approach would be to use LINQPad's beta Custom Visualizer API to embed FsEye into LINQPad (FsEye uses the same F# type signature printing algorithm as Unquote). This is also very simple, all you need to do is download LINQPad beta, download and reference FsEye.dll from the latest release of FsEye, then you can do e.g.

这篇关于如何在我自己的代码中生成类似于 FSI 的 F# 类型签名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆