Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Does this function exist?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Remi VANICAT <vanicat@l...>
Subject: Re: [Caml-list] Does this function exist?
Chris Hecker <checker@d6.com> writes:

> 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?

There is ioXML (http://pauillac.inria.fr/~ddr/IoXML/index.html) that
make more or less that (but with XML).

-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
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