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 TAA18446; Wed, 19 May 2004 19:23:58 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA18369 for ; Wed, 19 May 2004 19:23:57 +0200 (MET DST) Received: from kellthuzad.nerim.net (smtp-bounce.nerim.net [62.4.17.11]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i4JHNuSH012211 for ; Wed, 19 May 2004 19:23:56 +0200 Received: from kraid.nerim.net (smtp-103-wednesday.nerim.net [62.4.16.103]) by kellthuzad.nerim.net (Postfix) with ESMTP id EBC5A35A2 for ; Wed, 19 May 2004 19:18:56 +0200 (CEST) Received: from [192.168.0.2] (planar.net0.nerim.net [213.41.168.102]) by kraid.nerim.net (Postfix) with ESMTP id 6FB4A418EA for ; Wed, 19 May 2004 19:23:54 +0200 (CEST) Mime-Version: 1.0 (Apple Message framework v613) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: <504F4A75-A9B9-11D8-A6E5-00039310CAE8@kraid.nerim.net> Content-Transfer-Encoding: 7bit From: MAILER-DAEMON@kraid.nerim.net (Mail Delivery System) Subject: Re: [Caml-list] format4 query (Modified by Damien Doligez) Date: Wed, 19 May 2004 19:20:43 +0200 (CEST) To: damien.doligez@inria.fr X-Mailer: Apple Mail (2.613) X-Miltered: at concorde with ID 40AB982C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 damien:01 fmt:01 printf:01 kprintf:01 fmt:01 val:01 inferred:01 kprintf:01 printf:01 damien:01 nerim:01 evaluates:01 delivery:98 int:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On May 19, 2004, at 18:13, David J. Trombley wrote: > Right, as I said I can get simple examples to work. But I > can't get syntax such as > > # let g (l : listener) (k : int) fmt = > match k with > 0 -> 0 > | x -> Printf.kprintf l fmt; k;; > > val g : listener -> int -> ('a, unit, string, unit) > format4 -> int = > > to function, as you can see the format type has been > inferred to a type that is not useful at all. > > I'd like to use kprintf as a side effect to a function which > evaluates to some type, but I would not like that type or > the unit type of a ; evaluation to affect the format type. Here is the trick: the call to kprintf must always be the last thing that your function does. You get control back when kprintf calls your continuation function: let g (l : listener) (k : int) fmt = let cont s = match k with | 0 -> 0 | _ -> l s; k in Printf.kprintf cont fmt ;; Note that kprintf will be called in all cases, but that's unavoidable because it has to consume the arguments that will be passed to g after the fmt argument. -- Damien ------------------- 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