In F# Interactive (fsi), you can use AddPrinter
or AddPrinterTransformer
to provide pretty printing for a type in the interactive session. How can I add such a printer for a generic type? Using the wildcard _
for the type doesn't work:
> fsi.AddPrinter(fun (A : MyList<_>) -> A.ToString());;
The printer just isn't used.
Putting in a type parameter also gives a warning:
> 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'.
which is not what I want, either.