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=1.7 required=5.0 tests=AWL,DNS_FROM_RFC_POST, SPF_NEUTRAL 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 715D9BBAF for ; Sat, 10 Jan 2009 14:10:39 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AogBAG4taEnRVdoUmGdsb2JhbACTUj4BAQEBAQgJDAcRsSqLGwEDAQOFbIJo X-IronPort-AV: E=Sophos;i="4.37,244,1231110000"; d="scan'208";a="33541713" Received: from mail-bw0-f20.google.com ([209.85.218.20]) by mail4-smtp-sop.national.inria.fr with ESMTP; 10 Jan 2009 14:10:39 +0100 Received: by bwz13 with SMTP id 13so27357610bwz.3 for ; Sat, 10 Jan 2009 05:10:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=zmhfCaB6azg//hp0dyulMEVB1Cix1HQ0LF+N5xOYit0=; b=F+M5KC5W3H6TOdQzZvq2hU1SazjpF/oECuflBKN44NrCOW/QGT+vIvh8nztaRpFE8v oBQKjgB2Mx4JjQWBsWFe0kLR2vQxP2Yz1MXENGKKIEwflBc+1ndL52VU0JiI0CGPStQO BF22EsSZUbKOE4CGV6AF1OgMzycYcixbnBNOM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=dES984gM3kcRsz/zRbjuftSx1tC77ootGRmj2Zc2SWk1m4mMeknWx89DaJwF3X9zSR MEH/IjPCcBd8MoRpMvlOADkOAQeOX2Iuz3LEOgJQHMtgfKQbTN/KyRs8Ry4z26rlYmz4 Sfx5w0fMU2D+hqtaRW7tXwPMYL3YN3m1xuPrs= Received: by 10.103.224.17 with SMTP id b17mr9585645mur.61.1231593038511; Sat, 10 Jan 2009 05:10:38 -0800 (PST) Received: from ?192.168.0.124? (bur91-1-87-88-165-197.dsl.club-internet.fr [87.88.165.197]) by mx.google.com with ESMTPS id i7sm37787348mue.15.2009.01.10.05.10.37 (version=SSLv3 cipher=RC4-MD5); Sat, 10 Jan 2009 05:10:38 -0800 (PST) Sender: Arnaud Spiwack Message-ID: <49689E4E.5000300@lix.polytechnique.fr> Date: Sat, 10 Jan 2009 14:10:38 +0100 From: Arnaud Spiwack User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) MIME-Version: 1.0 To: Richard Jones Cc: Antoine Delignat-Lavaud , 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> <20090110125925.GA6231@annexia.org> In-Reply-To: <20090110125925.GA6231@annexia.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; lix:01 toplevel:01 ocaml:01 infers:01 ocaml:01 equivalently:01 toplevel:01 val:01 polymorphic:01 arnaud:01 arnaud:01 caml-list:01 int:01 int:01 expression:02 > It's a strange one ... when the if statement appears as a toplevel > statement, OCaml infers the type 'a list for the list: > It is not anyhow strange, it is how OCaml always does. It generalises types of variables introduced by a let (or equivalently at toplevel), types of other variables are not polymorphic. In the case of list it should be fairly clear, by the way, that the empty list is the only one that has type 'a list for all 'a. > # let el = [] ;; > val el : 'a list = [] > # if List.length el > 0 then (List.hd el)+(int_of_string (List.hd el)) else 0;; > - : int = 0 > # el ;; > - : 'a list = [] > > 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 > > Rich. > >