From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 51EC67EE25 for ; Fri, 25 Oct 2013 14:35:48 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of rdicosmo@gmail.com) identity=pra; client-ip=74.125.82.44; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="rdicosmo@gmail.com"; x-sender="rdicosmo@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of rdicosmo@gmail.com designates 74.125.82.44 as permitted sender) identity=mailfrom; client-ip=74.125.82.44; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="rdicosmo@gmail.com"; x-sender="rdicosmo@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wg0-f44.google.com) identity=helo; client-ip=74.125.82.44; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="rdicosmo@gmail.com"; x-sender="postmaster@mail-wg0-f44.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlEEAEdlalJKfVIslGdsb2JhbABZgz9OuQ+GYhYOAQEBAQcLCwkSKoIlAQEFJwsBDQEUJAEDDAEFBQ4KCSUPBSABBQEBIRMJh2wDDwQBAwWbGI9ghFAnDYllAQUMCo4EhF+BDQOYCYEwiySDSEGBZIJvgW8 X-IPAS-Result: AlEEAEdlalJKfVIslGdsb2JhbABZgz9OuQ+GYhYOAQEBAQcLCwkSKoIlAQEFJwsBDQEUJAEDDAEFBQ4KCSUPBSABBQEBIRMJh2wDDwQBAwWbGI9ghFAnDYllAQUMCo4EhF+BDQOYCYEwiySDSEGBZIJvgW8 X-IronPort-AV: E=Sophos;i="4.93,570,1378850400"; d="scan'208";a="38774231" Received: from mail-wg0-f44.google.com ([74.125.82.44]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 25 Oct 2013 14:35:25 +0200 Received: by mail-wg0-f44.google.com with SMTP id n12so3740244wgh.23 for ; Fri, 25 Oct 2013 05:35:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=z690vYHKZTQFtuF2Y9VSOpgo3CXhxWmjA4WXRmDNzQ8=; b=eMhNym/lUKkyQHg4TYCxpE5zVuSd1LOTYQlnQRQZ3BBkwy53BceOpZCc71l/dRDj5l qUbgWn94zVsufHKhostwHQKl7KhZTuI+HpRGrJsfIqcMfspUWuwGvvW793FfF2Cu1jIS BQrOWm0QJ+3CooRYAsDeLaLiZHRcxa9qJwimrfVE1+N8ui/F3nDrqJ4cRxlhWsEceZm4 IVnNzwuQXs7Zs5vJxfrzDgyhvefiPYFvuGWm4tgXvqQ5OglfZ2HF/LZy3jPlwpBTBzDP CwEfNjXQRn1MYkE4mfSkz96FnUuFI+tW+VB2hA+yk5lZ41hGA4JoSk2Pvn7nnArGWXNk ZMdQ== X-Received: by 10.194.82.229 with SMTP id l5mr139348wjy.85.1382704523214; Fri, 25 Oct 2013 05:35:23 -0700 (PDT) Received: from voyager ([81.56.44.163]) by mx.google.com with ESMTPSA id i8sm5703509wiy.6.2013.10.25.05.35.21 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 25 Oct 2013 05:35:22 -0700 (PDT) Sender: Roberto Di Cosmo Received: from dicosmo by voyager with local (Exim 4.80) (envelope-from ) id 1VZgbl-0000xM-Tb; Fri, 25 Oct 2013 14:35:17 +0200 Date: Fri, 25 Oct 2013 14:35:17 +0200 From: Roberto Di Cosmo To: Ivan Gotovchits Cc: Andreas Rossberg , Jacques Garrigue , OCaML List Mailing Message-ID: <20131025123517.GA21960@voyager> References: <97627FCD-30E1-45AD-A72B-CD423170C0AC@math.nagoya-u.ac.jp> <20131025082911.GB23798@voyager> <878uxhd62p.fsf@golf.niidar.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <878uxhd62p.fsf@golf.niidar.ru> User-Agent: Mutt/1.5.20 (2009-06-14) Subject: Re: [Caml-list] Equality between abstract type definitions Thanks Ivan, the potential confusion between type annotations in the code and type specifications in module interfaces is a very good point. Writing let f : 'a -> 'a = fun x -> x+1 will just boil down to defining val f : int -> int = On the other side, declaring val f : 'a -> 'a in a module signature actually *requires* the implementation to be at least as generic as 'a -> 'a, so a definition let f = fun x -> x+1 in the body will not work. Nevertheless, I would say that the difference is pretty easy to grasp, as soon as one explains that specifications are only introduced in modules signatures, with the val keyword. One may want to introduce type specifications in the code like in Haskell, but I am not sure that il will be much better for newbies... : let's write some code similar to the above one succ :: a -> a succ n = n+1 here is the system's answer No instance for (Num a) arising from a use of `+' In the expression: n + 1 In an equation for `succ': succ n = n + 1 Is this really more new-user friendly? -- Roberto On Fri, Oct 25, 2013 at 01:59:26PM +0400, Ivan Gotovchits wrote: > Roberto Di Cosmo writes: > > > > > I am curious to know why you consider this a pitfall: if it is > > not what people expect, it is probably because nobody explained > > their meaning to them properly, and I am quite interested in > > understanding how to explain this better. > > > > I think that people expect that an expression: > > ``` > let a : int = b > ``` > > is a declaration that value `a` has type int (Just like C'ish > `int a = b;`). But, indeed, it should be understood as a type > constraint. Thus the following, will be readily accepted by the > type checker (because we «constrain» a to be anything): > > ``` > let a : 'a = 12 > ``` > > The root of misunderstanding, I think, lies in that the same syntax is > used for type annotations and value specifications. Consider the > following example: > > ``` > module T : sig > val sum: 'a -> 'a -> 'a > end = struct > let sum: 'a -> 'a -> 'a = > fun x y -> x + y > end > ``` > > It looks like that the value sum has the same type in the module > specification and in the module implementation. So if compiler accepts > definition, it should accept that it conforms to the specification. > > Indeed, it's rather intuitional - this types do look the same! > > So, I think, that it should be clarified by someone, who knows OCaml and > English much better than me, what is the difference between this two > cases. And it would be great if it will be described in the manual, > too. > > > > > -- > (__) > (oo) > /------\/ > / | || > * /\---/\ > ~~ ~~ > ...."Have you mooed today?"... -- Roberto Di Cosmo ------------------------------------------------------------------ Professeur En delegation a l'INRIA PPS E-mail: roberto@dicosmo.org Universite Paris Diderot WWW : http://www.dicosmo.org Case 7014 Tel : ++33-(0)1-57 27 92 20 5, Rue Thomas Mann F-75205 Paris Cedex 13 Identica: http://identi.ca/rdicosmo FRANCE. Twitter: http://twitter.com/rdicosmo ------------------------------------------------------------------ Attachments: MIME accepted, Word deprecated http://www.gnu.org/philosophy/no-word-attachments.html ------------------------------------------------------------------ Office location: Bureau 3020 (3rd floor) Batiment Sophie Germain Avenue de France Metro Bibliotheque Francois Mitterrand, ligne 14/RER C ----------------------------------------------------------------- GPG fingerprint 2931 20CE 3A5A 5390 98EC 8BFC FCCA C3BE 39CB 12D3