From: Jean-Christophe Filliatre <filliatr@lri.fr>
To: Andrej.Bauer@andrej.com
Cc: Caml list <caml-list@inria.fr>
Subject: Re: [Caml-list] toplevel with pre-installed printers
Date: Fri, 20 Jan 2006 09:29:49 +0100 [thread overview]
Message-ID: <17360.40829.639123.509366@gargle.gargle.HOWL> (raw)
In-Reply-To: <43CFBE3E.1090808@andrej.com>
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)
next prev parent reply other threads:[~2006-01-20 8:30 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-19 16:28 Andrej Bauer
2006-01-19 16:53 ` [Caml-list] " Daniel Bünzli
2006-01-19 16:57 ` Eric Stokes
2006-01-19 17:08 ` Andrej Bauer
2006-01-19 17:49 ` Richard Jones
2006-01-19 19:12 ` Eric Cooper
2006-01-19 20:18 ` Richard Jones
2006-01-20 2:24 ` skaller
2006-01-20 16:49 ` David Brown
2006-01-20 19:29 ` skaller
2006-01-20 14:13 ` code17
2006-01-20 8:29 ` Jean-Christophe Filliatre [this message]
2006-01-20 13:13 ` [Caml-list] " Gerd Stolpmann
2006-01-19 19:40 Harrison, John R
2006-01-20 1:30 ` skaller
2006-01-20 20:19 Harrison, John R
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=17360.40829.639123.509366@gargle.gargle.HOWL \
--to=filliatr@lri.fr \
--cc=Andrej.Bauer@andrej.com \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).