0

As a follow-on to F# fsi.AddPrinter: Does AddPrinter have ability to take list apart?

I was not aware that type printers should provide for handling a list as input.

As such, are there any published standards for what is/should be required of a type printer?

Can you please provide references to examples of such code.

Community
  • 1
  • 1
Guy Coder
  • 24,501
  • 8
  • 71
  • 136

1 Answers1

3

I was not aware that type printers should provide for handling a list as input.

I advise you not to do so. If you do it, you break KISS principle and may surprise other team members with a strange way of displaying very standard 'T list. Just provide a printer for 'T and let F# Interactive figure out the rest.

You may consider this case

type Theorem = Axiom list

where you care about Theorem and would like to display it in an appropriate way. Then it makes sense to define a printer so that a Theorem is printed out as

:- axiom 1, axiom 2, ..., axiom n.

This example isn't a very good example because you probably prefer a type-safe solution

type Theorem = Theorem of Axiom list

That said, you may ask whether you should go for fsi.AddPrinter at all. The fsi.AddPrinter bits may be there due to legacy reasons. More universal solutions are to override ToString() methods and to use StructuredFormatDisplay attribute in order that you have good printers for both fsc and fsi, which work with printf "%A", printf "%O", etc.

pad
  • 41,040
  • 7
  • 92
  • 166