From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id D38EFBB84 for ; Sun, 11 Jan 2009 17:32:04 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ag8BAJOtaUnUGyoClGdsb2JhbACUEAEBAQEJCwgJEQO8JIVv X-IronPort-AV: E=Sophos;i="4.37,249,1231110000"; d="scan'208";a="33576493" Received: from smtp2-g21.free.fr ([212.27.42.2]) by mail4-smtp-sop.national.inria.fr with ESMTP; 11 Jan 2009 17:32:03 +0100 Received: from smtp2-g21.free.fr (localhost [127.0.0.1]) by smtp2-g21.free.fr (Postfix) with ESMTP id 4D3854B0188; Sun, 11 Jan 2009 17:31:57 +0100 (CET) Received: from [192.168.1.3] (che78-2-82-237-71-191.fbx.proxad.net [82.237.71.191]) by smtp2-g21.free.fr (Postfix) with ESMTP id 026FE4B019E; Sun, 11 Jan 2009 17:31:54 +0100 (CET) Message-ID: <496A1EFA.8020501@inria.fr> Date: Sun, 11 Jan 2009 17:31:54 +0100 From: Xavier Leroy User-Agent: Thunderbird 2.0.0.4 (X11/20070620) MIME-Version: 1.0 To: Antoine Delignat-Lavaud Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Why does value restriction not apply to the empty list ? References: <496887BE.8030804@dptinfo.ens-cachan.fr> In-Reply-To: <496887BE.8030804@dptinfo.ens-cachan.fr> X-Enigmail-Version: 0.95.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ocaml:01 ocaml's:01 bool:01 bool:01 parametric:01 polymorphism:01 polymorphism:01 constants:01 polymorphic:01 polymorphic:01 wrote:01 wrote:01 integer:01 caml-list:01 monomorphic:01 Antoine Delignat-Lavaud wrote: > I chose to solve the problem of polymorphic references by adding value > restriction* to my inferer, using ocaml to check my results. > Not knowing whether the empty list should be considered a value or an > expression, I copied Ocaml's behavior and made it a value. Yes, the empty list is a value, like all other constants. > As a result, my inferer gave the following expression the integer type : > let el = [] in if hd el then 1 else hd el ;; > which is the expected result since el has polymorphic type 'a list > but does not look right because it is used as both a bool list and an > int list. It is perfectly right. The empty list can of course be used both as a bool list and an int list; that's exactly what parametric polymorphism is all about. Richard Jones wrote: > But the same if statement within a function definition causes an error: > > # let f el = > if List.length el > 0 then (List.hd el)+(int_of_string (List.hd el)) else 0;; > ^^^^^^^^^^ > This expression has type int but is here used with type string This is Hindley-Milner polymorphism at work: only "let"-bound variables can have polymorphic types, while function parameters are monomorphic. - Xavier Leroy