Date: Mon, 29 Mar 1999 18:31:50 +0200
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: John Prevost <prevost@maya.com>, caml-list@inria.fr
Subject: Re: another approach to sprintf (Re: ocaml 2.02 bug: curried printf)
In-Reply-To: <ya2pv5ywuem.fsf@zarya.maya.com>; from John Prevost on Wed, Mar 24, 1999 at 02:37:53PM -0500
> It does, however, mean that people can extend the set of patterns that
> can be used in printf in a more palatable way than the %a mechanism.
> Especially with neat things like Danvy's "lis" combinator.
This is a good point.
> It also allows me to take two formats and concatenate them, like this:
> let foo = int $ lit " " $ int $ string
> let bar = lis int $ lit "!"
> let zum = foo $ bar
> which you can't do with O'Caml's format strings.
You almost can. The following definition works as long as you
don't have %a and %t escapes in your format strings:
let (^^) (s1 : ('a, 'b, 'c) format) (s2 : ('c, 'b, 'd) format) =
(Obj.magic (Obj.magic s1 ^ Obj.magic s2) : ('a, 'b, 'd) format)
If you have occurrences of %a or %t in s1, the typing becomes wrong.
This could be fixed by adding a fourth type parameter to the "format"
type constructor, but I agree this is getting really complicated.
- Xavier Leroy
This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:21 MET