在 F# Interactive (fsi) 中,您可以使用AddPrinter
或AddPrinterTransformer
为交互式会话中的类型提供漂亮的打印。如何为泛型类型添加这样的打印机?对类型使用通配符_
不起作用:
> fsi.AddPrinter(fun (A : MyList<_>) -> A.ToString());;
只是没有使用打印机。
放入类型参数也会发出警告:
> fsi.AddPrinter(fun (A : MyList<'T>) -> A.ToString());;
fsi.AddPrinter(fun (A : MyList<'T>) -> A.ToString());;
-------------------------------^^
d:\projects\stdin(70,51): warning FS0064: This construct causes code
to be less generic than indicated by the type annotations. The type
variable 'T been constrained to be type 'obj'.
这也不是我想要的。