From: "gabriele renzi" <[EMAIL PROTECTED]>

Again, my OO background would tell me to define a #inspect method in every
class I'm defining, and then just let the Inspector call that.
But how is this done in ML?

If you define your own abstract types - e.g. via applying a functor - then you can register simple printers for them with the inspector. For example,

 structure Set = MkRedBlackSet String
 fun setToString s =
"{" ^ String.concatWith ", " (map (fn x => "\""^String.toString x^"\"") (Set.toList s)) ^ "}"

 Inspector.register setToString

Now you can do

 val s = Set.fromList ["a", "c", "b"]

 inspect s

In a similar vein, you can register the same printer to be used by the REPL:

 > Print.register setToString
 val it : unit = ()
 > val s = Set.fromList ["a", "c", "b"]
 val s : Set.set = {"a", "b", "c"}
 >

Hope this helps,
- Andreas


_______________________________________________
alice-users mailing list
[email protected]
http://www.ps.uni-sb.de/mailman/listinfo/alice-users

Reply via email to