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 804F1BBAF for ; Tue, 26 Oct 2010 17:55:32 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AswAAO6WxkzUGyoCkWdsb2JhbACTWI11FQEBAQEJCwoHEQMfwHmFSASKU4MIGQ X-IronPort-AV: E=Sophos;i="4.58,241,1286143200"; d="scan'208";a="64103386" Received: from smtp2-g21.free.fr ([212.27.42.2]) by mail3-smtp-sop.national.inria.fr with ESMTP; 26 Oct 2010 17:55:31 +0200 Received: from [127.0.0.1] (unknown [81.57.61.170]) by smtp2-g21.free.fr (Postfix) with ESMTP id 0BD8F4B01E1 for ; Tue, 26 Oct 2010 17:55:24 +0200 (CEST) Message-ID: <4CC6F9E9.9090003@free.fr> Date: Tue, 26 Oct 2010 17:55:21 +0200 From: Emmanuel Dieul User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.2.11) Gecko/20101013 Thunderbird/3.1.5 MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: type inference problem with Printf.sprintf ? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 101026-0, 26/10/2010), Outbound message X-Antivirus-Status: Clean X-Spam: no; 0.00; inference:01 printf:01 sprintf:01 inference:01 printf:01 sprintf:01 ocaml:01 compiler:01 1900:98 1900:98 unix:01 unix:01 int:01 int:01 expression:02 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) in function date -> Printf.sprintf "%s/%s/%l %s:%s:%s" (format_valeur(date.Unix.tm_mday) : string) (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) ;; The "format_valeur" function has type "int -> string". The "format_date" function has type "Unix.tm -> string". The problem is about the Printf.sprintf function. In fact, if I don't force the type of every date field (like "(format_valeur(date.Unix.tm_mday) : string)"), the ocaml 3.12.0 compiler detects a type error. This example 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) ;; generates this error around the "%s/%s/%l %s:%s:%s" string : Error: This expression has type (string -> string -> int -> string -> string -> string -> 'a -> 'b, unit, string, string, string, 'a -> 'b) format6 but an expression was expected of type (string -> string -> int -> string -> string -> string -> 'a -> 'b, unit, string) format = (string -> string -> int -> string -> string -> string -> 'a -> 'b, unit, string, string, string, string) format6 Did I do something wrong or is there a real problem ? Emmanuel