Printing F# discriminated union

孤者浪人 提交于 2019-11-30 20:16:21

Have you tried printfn "%A" ast? The %A specifier takes into consideration the StructuredFormatDisplayAttribute[MSDN], if present.

Kwang Yul Seo

To convert a discriminated union into a string, you should use sprintf "%A" ast instead of ast.ToString().

If you want Enum.GetName, you can use Microsoft.FSharp.Reflection namespace. See What is the Enum.GetName equivalent for F# union member?.

In addition to Daniel's comment, here is a good blog article explaining how to format it in whatever way you'd wish:

http://blogs.msdn.com/b/dsyme/archive/2010/01/08/some-tips-and-tricks-for-formatting-data-in-f-interactive-and-a-in-sprintf-printf-fprintf.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!