caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David Allsopp <dra-news@metastack.com>
To: Emmanuel Dieul <emmanuel.dieul@free.fr>,
	"caml-list@yquem.inria.fr" <caml-list@yquem.inria.fr>
Subject: RE: [Caml-list] type inference problem with Printf.sprintf ?
Date: Tue, 26 Oct 2010 21:41:24 +0000	[thread overview]
Message-ID: <E51C5B015DBD1348A1D85763337FB6D92C573E97@Remus.metastack.local> (raw)
In-Reply-To: <4CC6F9E9.9090003@free.fr>

Emmanuel Dieul wrote:
> Hi everyone.
> 
> I've just noticed a type inference problem (or am I wrong ?). Here's my
> example :
> 
> let format_date =
>    let format_valeur = 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 specification 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.tm_mon + 1) (date.Unix.tm_year + 1900) date.Unix.tm_hour date.Unix.tm_min date.Unix.tm_sec

It's worth having a complete read of the top of the Printf page in the standard library reference just to see the things it can do. 


David 


      parent reply	other threads:[~2010-10-26 21:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-26 15:55 Emmanuel Dieul
2010-10-26 16:04 ` [Caml-list] " Mathias Kende
2010-10-26 16:10   ` Emmanuel Dieul
2010-10-26 21:44     ` Arlen Cuss
2010-10-27 11:30       ` Richard Jones
2010-11-03 13:47         ` Gregory Bellier
2010-11-03 14:43           ` Sylvain Le Gall
2010-11-03 15:33             ` [Caml-list] " Benedikt Grundmann
2010-11-03 16:23               ` Dario Teixeira
2010-10-26 21:41 ` David Allsopp [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E51C5B015DBD1348A1D85763337FB6D92C573E97@Remus.metastack.local \
    --to=dra-news@metastack.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=emmanuel.dieul@free.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).