In F # Interactive (fsi), è possibile utilizzare AddPrinter
o AddPrinterTransformer
per fornire una bella stampa per un tipo nella sessione interattiva. Come posso aggiungere una stampante di questo tipo per un tipo generico? Utilizzando il carattere jolly _
per il tipo non funziona:Come si aggiunge una stampante carina per un tipo generico a fsi?
> fsi.AddPrinter(fun (A : MyList<_>) -> A.ToString());;
La stampante semplicemente non viene utilizzato.
Mettere in un parametro di tipo dà anche un avvertimento:
> 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'.
che non è quello che voglio, neanche.
Sono abbastanza sicuro che questo non è possibile. Un argomento di tipo richiede un tipo concreto. – Daniel
Puoi sovrascrivere 'ToString' per' MyList <'T> '? – Daniel