From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id DDCF7BB9C for ; Fri, 20 Jan 2006 09:30:26 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k0K8UQBv014446 for ; Fri, 20 Jan 2006 09:30:26 +0100 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 JAA21972 for ; Fri, 20 Jan 2006 09:30:25 +0100 (MET) Received: from ext.lri.fr (ext.lri.fr [129.175.15.4]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k0K8UPFn014443 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 20 Jan 2006 09:30:25 +0100 Received: from smtp.lri.fr (serveur3-5 [129.175.3.5]) by ext.lri.fr (Postfix) with ESMTP id 309DF202456; Fri, 20 Jan 2006 09:30:25 +0100 (CET) Received: from pc9-152 (pc9-152 [129.175.9.152]) by smtp.lri.fr (Postfix) with ESMTP id E7297CED98; Fri, 20 Jan 2006 09:30:24 +0100 (CET) Received: from filliatr by pc9-152 with local (Exim 3.36 #1 (Debian)) id 1Ezrec-0008KM-00; Fri, 20 Jan 2006 09:29:54 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <17360.40829.639123.509366@gargle.gargle.HOWL> Date: Fri, 20 Jan 2006 09:29:49 +0100 To: Andrej.Bauer@andrej.com Cc: Caml list Subject: Re: [Caml-list] toplevel with pre-installed printers In-Reply-To: <43CFBE3E.1090808@andrej.com> References: <43CFBE3E.1090808@andrej.com> X-Mailer: VM 7.19 under Emacs 21.4.1 From: Jean-Christophe Filliatre X-Virus-Scanned: by amavisd-new at lri.fr X-Miltered: at nez-perce with ID 43D09FA2.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 43D09FA1.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 toplevel:01 filliatre:01 filliatr:01 lri:01 andrej:01 trivial:01 toplevel:01 ocaml:01 lident:01 topdirs:01 topdirs:01 lident:01 ocaml:01 cmo:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Hello, Andrej Bauer writes: > This seems like a trivial question, but I do not know the answer: > how do I create either a toplevel (or a shell script which appears to be > a toplevel) with pre-installed pretty-printers (and pre-opened modules, > for that matter)? I learnt a trick to do that from David Monniaux's GMP interface. First define your pretty-printers using the Ocaml module Format. For instance, the GMP pretty-printers look like == gmp_pp.ml ========================================================= open Gmp open Format let z z = print_string (Z.string_from z) let q q = ... ====================================================================== then introduce another file installing the pretty-printers: == install_gmp_pp.ml ================================================= (* This is a hack to install the pretty-printers in the customized toplevel. *) (* Caml longidents. *) type t = | Lident of string | Ldot of t * string | Lapply of t * t let _ = Topdirs.dir_directory "+creal" let _ = Topdirs.dir_install_printer Format.std_formatter (Obj.magic (Ldot (Lident "Gmp_pp", "z")) : 'a) let _ = Topdirs.dir_install_printer Format.std_formatter (Obj.magic (Ldot (Lident "Gmp_pp", "q")) : 'a) ====================================================================== Finally, build your ocaml toplevel the usual way, linking the two files above: ====================================================================== ocamlgmp: gmp.cma gmp_pp.cmo install_gmp_pp.cmo ocamlmktop -custom -o $@ $^ ====================================================================== I know this is a hack (the infamous Obj.magic is used and the Caml longident type could change in a next ocaml version) but it works fine. Hope this helps, -- Jean-Christophe Filliātre (http://www.lri.fr/~filliatr)