Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] a generic print (ugly hack)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: pad@r...
Subject: [Caml-list] a generic print (ugly hack)

the goal is to allow the programmer to write in his program for instance:

 let _ = print_string (generic_print [[1;3];[2;9;8];[3;4]] "int list list") in
 ...
 let _ = print_string (generic_print [1;3;2;9;8;3;4] "int list") in
 let v = ... (* big computation, big data structure *)
 let _ = print_string (generic_print v "(int * float * color) assoc") in
 ...
  

and to get on stdout:
 [[1; 3]; [2; 9; 8]; [3; 4]]
 [1; 3; 2; 9; 8; 3; 4]
 [(1, 2.02, Red); (2, 4.02, Yellow)];


the type of generic_print is
 'a -> string -> string

code:
 http://www.irisa.fr/prive/padiolea/hacks/generic_print.ml

the principle is that the toplevel of O'Caml know how to print value,
so by "reusing" the toplevel, our program can too.


It is slow, ugly, not robust,  but it can be helpful.
any suggestion or critics are welcome.


-- 
Yoann  Padioleau,  INSA de Rennes, France   
Opinions expressed here are only mine. Je n'écris qu'à titre personnel.
**____   Get Free. Be Smart.  Simply use Linux and Free Software.   ____**

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners