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 p8HC8Z3M009188 for ; Sat, 17 Sep 2011 14:08:35 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhMBACeNdE7ZSMDqgGdsb2JhbABBp2AUAQELCwsFFgMigVMBAQQBOg0yBQsBAwchJQ8BBA0bIROHdwKmYY1JhngEmGaEdIce X-IronPort-AV: E=Sophos;i="4.68,398,1312149600"; d="scan'208";a="120216787" Received: from fmmailgate03.web.de ([217.72.192.234]) by mail1-smtp-roc.national.inria.fr with ESMTP; 17 Sep 2011 14:08:30 +0200 Received: from smtp04.web.de ( [172.20.0.225]) by fmmailgate03.web.de (Postfix) with ESMTP id E561619995BC5; Sat, 17 Sep 2011 14:08:29 +0200 (CEST) Received: from [78.43.204.177] (helo=frosties.localnet) by smtp04.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #2) id 1R4th7-0008Mx-00; Sat, 17 Sep 2011 14:08:29 +0200 Received: from mrvn by frosties.localnet with local (Exim 4.76) (envelope-from ) id 1R4th6-0001W8-Nx; Sat, 17 Sep 2011 14:08:28 +0200 From: Goswin von Brederlow To: Gabriel Scherer Cc: Guillaume Yziquel , Philippe Veber , Goswin von Brederlow , caml-list@inria.fr References: <87ty8uc5ph.fsf@frosties.localnet> <20110903103653.GX15100@localhost> <20110903114625.GA15100@localhost> Date: Sat, 17 Sep 2011 14:08:28 +0200 In-Reply-To: (Gabriel Scherer's message of "Sat, 3 Sep 2011 14:15:35 +0200") Message-ID: <87bouj2wxv.fsf@frosties.localnet> User-Agent: Gnus/5.110009 (No Gnus v0.9) XEmacs/21.4.22 (linux, no MULE) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX19WzBJ1xGvEkbXY19KWx2snIrUaCV/PloSTtNMu 8747MlS+GzxehTqu2mEKJfUExOHLSMLbJ0LB7yr9mnTts4QBkg kgq6pQ1MM= Subject: Re: [Caml-list] Odd failure to infer types Gabriel Scherer writes: > Indeed, a let-bound [] is generalized to a polymorphic ('a list), while a > let-bound (ref []), or (Array.make n []), is not generalized. It would be > unsound to do so as if you had a reference to a polymorphic ('a list) you could > add elements of different types in the list. > > When a type variable is not generalized (polymorphic), it stays an "unknown" of > the type system until it is unified to a known type: > > # let r = ref [];; > val r : '_a list ref = {contents = []} > # r := 1 :: !r;; > - : unit = () > # r;; > - : int list ref = {contents = [1]} > > '_a is sometimes called a "weakly polymorphic variable", in fact it is not > polymorphic at all. It is just an unknown. > > In the code example above, the real type for '_a could be determined after two > phrases in the top level. It may also happen as a compilation unit (if the code > was written in a file instead of fed phrase-per-phrase to the toplevel). We > wouldn't observe the intermediary '_a inferred type, as the type are inferred > globally. I think you are missing the point. I totaly get why it must be '_a instead if 'a. My question is why it doesn't infer the full type from the call to the print function. In my case the type inferences outputs something like this (using the above example): > # let r = ref [];; > val r : '_a list ref = {contents = []} > # r := 1 :: !r;; > - : unit = () > # r;; > - : '_a list ref = {contents = [1]} I see my print call as equivalent to '1 :: !r'. MfG Goswin