English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
type inference problem with Printf.sprintf ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-10-26 (21:43)
From: David Allsopp <dra-news@m...>
Subject: RE: [Caml-list] type inference problem with Printf.sprintf ?
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.