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 9F872BBAF for ; Tue, 26 Oct 2010 23:43:35 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArwBAMrnxkxRZ90wkWdsb2JhbAChVRUBAQEBCQsKBxEDH8E2hUgEilM X-IronPort-AV: E=Sophos;i="4.58,242,1286143200"; d="scan'208";a="64226605" Received: from mtaout02-winn.ispmail.ntl.com ([81.103.221.48]) by mail3-smtp-sop.national.inria.fr with ESMTP; 26 Oct 2010 23:43:35 +0200 Received: from aamtaout01-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout02-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20101026214334.XTZZ7723.mtaout02-winn.ispmail.ntl.com@aamtaout01-winn.ispmail.ntl.com>; Tue, 26 Oct 2010 22:43:34 +0100 Received: from romulus.metastack.com ([81.102.132.77]) by aamtaout01-winn.ispmail.ntl.com (InterMail vG.3.00.04.00 201-2196-133-20080908) with ESMTP id <20101026214334.EZRL20122.aamtaout01-winn.ispmail.ntl.com@romulus.metastack.com>; Tue, 26 Oct 2010 22:43:34 +0100 Received: from remus.metastack.local ([172.16.0.1]) by romulus.metastack.com (8.14.2/8.14.2) with ESMTP id o9QLhVmG012567 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Tue, 26 Oct 2010 22:43:31 +0100 Received: from Remus.metastack.local ([fe80::547c:3c42:e1da:eda2]) by Remus.metastack.local ([fe80::547c:3c42:e1da:eda2%11]) with mapi; Tue, 26 Oct 2010 22:41:25 +0100 From: David Allsopp To: Emmanuel Dieul , "caml-list@yquem.inria.fr" Subject: RE: [Caml-list] type inference problem with Printf.sprintf ? Thread-Topic: [Caml-list] type inference problem with Printf.sprintf ? Thread-Index: AQHLdSX2kpKdyjwjT0Cv+4Tyk7oGEZNTwNNA Date: Tue, 26 Oct 2010 21:41:24 +0000 Message-ID: References: <4CC6F9E9.9090003@free.fr> In-Reply-To: <4CC6F9E9.9090003@free.fr> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Organization: MetaStack Solutions Ltd. X-Scanned-By: MIMEDefang 2.65 on 81.102.132.77 X-Cloudmark-Analysis: v=1.1 cv=DhNl2YeytwJssBBGe49HJX82LNDFEEVkpVB34RXKaPo= c=1 sm=0 a=cYg1H-ekPsAA:10 a=kj9zAlcOel0A:10 a=xqWC_Br6kY4A:10 a=BTXPgwBeHAagDXuV9PYA:9 a=PcT526lbKcs7j-M0KY3QuU20sukA:4 a=CjuIK1q_8ugA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 X-Spam: no; 0.00; inference:01 printf:01 sprintf:01 inference:01 printf:01 sprintf:01 1900:98 wrote:01 unix:01 unix:01 integer:01 caml-list:01 int:01 string:02 noting:02 Emmanuel Dieul wrote: > Hi everyone. >=20 > I've just noticed a type inference problem (or am I wrong ?). Here's my > example : >=20 > let format_date =3D > let format_valeur =3D function valeur -> > (if valeur < 10 then "0" else "") ^ (string_of_int valeur) Your main problem has already been answered but it's worth noting that you = can eliminate this function entirely by using "%02l" in your format specifi= cation and passing the integer values from your time structure directly to = give: Printf.sprintf "%02l/%02l/%l %02l:%02l:%02l" date.Unix.tm_mday (date.Unix.t= m_mon + 1) (date.Unix.tm_year + 1900) date.Unix.tm_hour date.Unix.tm_min da= te.Unix.tm_sec It's worth having a complete read of the top of the Printf page in the stan= dard library reference just to see the things it can do.=20 David=20