From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 919DDBBAF for ; Tue, 26 Oct 2010 23:44:36 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EAPboxkyt/9A2/2dsb2JhbACDH542ca88kgGBIoMydASNWw X-IronPort-AV: E=Sophos;i="4.58,242,1286143200"; d="scan'208";a="64226779" Received: from sairyx.org ([173.255.208.54]) by mail3-smtp-sop.national.inria.fr with ESMTP; 26 Oct 2010 23:44:17 +0200 Received: by sairyx.org (Postfix, from userid 5001) id 5105EC775; Tue, 26 Oct 2010 21:44:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on sairyx.org X-Spam-Level: Received: from [192.168.0.104] (220.253-229-205.VIC.netspace.net.au [220.253.229.205]) (Authenticated sender: celtic@sairyx.org) by sairyx.org (Postfix) with ESMTPSA id 95522C770; Tue, 26 Oct 2010 21:44:13 +0000 (UTC) Subject: Re: [Caml-list] type inference problem with Printf.sprintf ? From: Arlen Cuss To: Emmanuel Dieul Cc: Mathias Kende , caml-list@yquem.inria.fr In-Reply-To: <4CC6FD65.7080603@free.fr> References: <4CC6F9E9.9090003@free.fr> <1288109042.11135.77.camel@bohrium.pps.jussieu.fr> <4CC6FD65.7080603@free.fr> Content-Type: text/plain; charset="UTF-8" Date: Wed, 27 Oct 2010 08:44:10 +1100 Message-ID: <1288129450.2986.3.camel@asu> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 Content-Transfer-Encoding: 8bit X-Spam: no; 0.00; inference:01 printf:01 sprintf:01 0200,:01 printf:01 sprintf:01 abstr:01 arlen:98 celtic:98 mathias:98 1900:98 1900:98 mathias:98 unix:01 unix:01 > Le 26/10/2010 18:04, Mathias Kende a écrit : > > Le mardi 26 octobre 2010 à 17:55 +0200, Emmanuel Dieul a écrit : > >> let format_date = > >> let format_valeur = function valeur -> > >> (if valeur< 10 then "0" else "") ^ (string_of_int valeur) > >> in > >> function date -> > >> Printf.sprintf "%s/%s/%l %s:%s:%s" > >> format_valeur(date.Unix.tm_mday) > >> (format_valeur(date.Unix.tm_mon + 1) : string) > >> (date.Unix.tm_year + 1900) > >> (format_valeur(date.Unix.tm_hour) : string) > >> (format_valeur(date.Unix.tm_min) : string) > >> (format_valeur(date.Unix.tm_sec) : string) > >> ;; By the way, consider using this: Printf.sprintf "%02d/%02d/%l %02d:%02d:%02d" date.Unix.tm_mday (date.Unix.tm_mon + 1) (date.Unix.tm_year + 1900) date.Unix.tm_hour date.Unix.tm_min date.Unix.tm_sec;; .. to make format_valeur redundant. Or, you could even use CalendarLib to do pretty printing: # open CalendarLib;; # Calendar.now ();; - : CalendarLib.Calendar.t = # Printer.Calendar.print "%d/%m/%Y %H:%M:%S\n" (Calendar.now ());; 26/10/2010 21:43:43 - : unit = () # > >> > > Here, the argument to the Printf.sprintf function are : > > "%s/%s/%l %s:%s:%s", format_valeur, date.Unix.tm_mday, ... > > > > Just add parenthesis around (format_valeur date.Unix.tm_mday) (but > > without any type annotation) to pass the _result_ of this application to > > the sprintf function. You don't need parenthesis around the argument of > > the function though. > > > > Mathias > > >