From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id AAA15128; Tue, 10 Sep 2002 00:05:38 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA15030 for ; Tue, 10 Sep 2002 00:05:38 +0200 (MET DST) Received: from relay.pair.com (relay1.pair.com [209.68.1.20]) by nez-perce.inria.fr (8.11.1/8.11.1) with SMTP id g89M5b912825 for ; Tue, 10 Sep 2002 00:05:37 +0200 (MET DST) Received: (qmail 16687 invoked from network); 9 Sep 2002 22:05:34 -0000 Received: from node-d8e9cca2-sfo-onnet.worldcom.com (HELO checkerlap.d6.com) (216.233.204.162) by relay1.pair.com with SMTP; 9 Sep 2002 22:05:34 -0000 X-pair-Authenticated: 216.233.204.162 Message-Id: <4.3.2.7.2.20020909144531.04529c20@mail.d6.com> X-Sender: checker@mail.d6.com X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Date: Mon, 09 Sep 2002 15:05:22 -0700 To: Lukasz Lew , John Prevost From: Chris Hecker Subject: Re: [Caml-list] Does this function exist? Cc: caml-list@inria.fr In-Reply-To: References: <86hegzarek.fsf@laurelin.dementia.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >I can use printf, but it isn't very easy to write when you have i.e. >list of pairs of lists. And i believe that there is unversal ``print''. >Can you help? This has gone around before, and I think it's impossible because there's no type information available at runtime. However, it seems like it would solve 90% of the problems if we could generate the code for such a function for a specific type using a tool, like camlp4 or something, and then compile that in when we want it. In other words, say I have this: type foo = A of int | B of int list Then have camlp4 generate let print_foo fmt f = Format.fprintf fmt "@[foo = "; begin match f with A i -> Format.fprintf fmt "A %d" i | B il -> Format.fprintf fmt "B [%s]" (List.fold_left ~f:(fun s i -> s ^ Printf.sprintf "%s%d" (if s <> "" then "; " else "") i) ~init:"" il) end; Format.fprintf fmt "@]" or whatever (you'd probably want it to just return a string so you could compose them, but then you'd want the formatting stuff in there, so it's unclear exactly which would be better...maybe Format.sprintf works). The idea is you don't want to have to write that code by hand, but generating it would be fine. Is this something camlp4 can do? Chris ------------------- 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