F# Interactive is great for exploring new API's. What would be even more helpful is if I could change what an object prints. By default, they just print their full class name. It would be awesome if I could have certain classes print something more meaningfull.

The InteractiveSession object (fsi) has a function called AddPrinter which does exactly what you are looking for.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 

> type Point = { x:int; y:int };;

type Point = {x: int;
              y: int;}

> let p = {x=1;y=2};;

val p : Point

> p;;
val it : Point = {x = 1;
                  y = 2;}
> fsi.AddPrinter( fun (p:Point) -> sprintf "(%i,%i)" p.x p.y );;
val it : unit = ()
> p;;
val it : Point = (1,2)
>
By on 5/31/2008 12:44 AM ()

It sounds like you want your classes to implement the StructuredFormat.IFormattable interface, see [link:www.intellifactory.com]

Stephan

By on 5/30/2008 2:53 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper