From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p665BHiW015953 for ; Wed, 6 Jul 2011 07:11:17 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuYAAIXtE05N6B+lmWdsb2JhbABTEKgSAQEBAQEICwsHFCWIegLEBYY2BIdAj3qLCzw X-IronPort-AV: E=Sophos;i="4.65,484,1304287200"; d="scan'208";a="112618645" Received: from fe02x03-cgp.akado.ru (HELO akado.ru) ([77.232.31.165]) by mail1-smtp-roc.national.inria.fr with ESMTP; 06 Jul 2011 07:11:11 +0200 X-Drweb-SpamState: no X-Drweb-SpamScore: -200 X-DrWeb-SpamReason: @!Recipients (-100); (-100) X-Drweb-SpamState-Num: 0 X-Spam-Level: Received: from [10.0.66.9] ([10.0.66.9] verified) by fe02-cgp.akado.ru (CommuniGate Pro SMTP 5.2.13) with ESMTPS id 219253443; Wed, 06 Jul 2011 09:11:10 +0400 Date: Wed, 6 Jul 2011 09:11:09 +0400 (MSD) From: malc X-X-Sender: malc@linmac To: Jacques Garrigue cc: caml-list@inria.fr In-Reply-To: <098226D8-77AA-4F80-97A5-F72F47C6A98E@math.nagoya-u.ac.jp> Message-ID: References: <098226D8-77AA-4F80-97A5-F72F47C6A98E@math.nagoya-u.ac.jp> User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: Re: [Caml-list] Type inference and marshalling On Wed, 6 Jul 2011, Jacques Garrigue wrote: > On 2011/07/05, at 22:59, malc wrote: > > > Perhaps someone could explain why following behaves the way it does: > > > > ~$ ocaml > > Objective Caml version 3.11.2 > > > > # let f ic = let i = input_value ic in let j = i + 1 in LargeFile.seek_in ic i;; > > Warning Y: unused variable j. > > val f : in_channel -> unit = > > The return type of input_value being 'a, which gets generalized by the > relaxed value restriction, i gets the polymorphic type "forall 'a. 'a". > So you can use it both as an int and an int64. > ==> input_value is an unsafe function, you should always write a type > annotation on its return type. Sure i'm well aware of that, but to me "let j = i + 1" means that i has type int and after that "LargeFile.seek ic i" makes no sense yet is accepted by the type checker. > > > # let f ic = let i = input_value ic in let j = i + 1 in LargeFile.seek_in ic j;; > > Error: This expression has type int but an expression was expected of type > > int64 > > j being the result of an integer addition, it has type int, and cannot be used > as int64. > > Jacques > > -- mailto:av1474@comtv.ru