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 p7EE1G5v032306 for ; Sun, 14 Aug 2011 16:01:16 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsgDADzUR07RVdY2imdsb2JhbABBmDqHMwGIAggUAQEBCgkNBxIGIYFAAQEBAQIBEgITGQEbEgsBAwELBgULDQ0hIQIRAQUBChIGExIQh04CApU0Cow2glWDTDuIbQIDBoViXwSCUZBBhjSDQoJjPINi X-IronPort-AV: E=Sophos;i="4.67,369,1309730400"; d="scan'208,217";a="115817579" Received: from mail-bw0-f54.google.com ([209.85.214.54]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 14 Aug 2011 16:01:10 +0200 Received: by bkat8 with SMTP id t8so5019618bka.27 for ; Sun, 14 Aug 2011 07:01:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=subject:mime-version:content-type:from:in-reply-to:date:cc :message-id:references:to:x-mailer; bh=rJgSVXs0vl2+iT/FZF/kzY4lkw+0TjBZrwvptOE3PXY=; b=w0eqzzGmWL/5xWj2QYd1nCBmeIXdkhlcxvj8AtmgQaVQGS7kIxFI0ct0AN9lbZB+Sb 36zLjeHmC7dLTudQnkLEXl95qDlhe+PU6bj8vcfe/IVAsrV+jWnYF6OWx70R+r07xThB 1++viOpMTJ7z0Nc0A1u3TIUGsDYiPga+XRZ54= Received: by 10.204.231.197 with SMTP id jr5mr507942bkb.155.1313330469115; Sun, 14 Aug 2011 07:01:09 -0700 (PDT) Received: from ruslan-macbook.lan (ppp-93-104-69-209.dynamic.mnet-online.de [93.104.69.209]) by mx.google.com with ESMTPS id q1sm1312426faa.3.2011.08.14.07.01.06 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 14 Aug 2011 07:01:07 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: multipart/alternative; boundary=Apple-Mail-3-15940969 From: Ruslan Ledesma Garza In-Reply-To: Date: Sun, 14 Aug 2011 16:03:09 +0200 Cc: OCaml List Message-Id: References: <1F991690-DC08-4BF6-BB41-6B9402C043FC@gmail.com> To: Gabriel Scherer X-Mailer: Apple Mail (2.1084) Subject: Re: [Caml-list] Type generalization problem --Apple-Mail-3-15940969 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=iso-8859-1 I'm so happy now. :D=20 Thanks a lot! Rusl=E1n. On Aug 14, 2011, at 3:55 PM, Gabriel Scherer wrote: > You have hit the "value restriction": > http://caml.inria.fr/resources/doc/faq/core.en.html#eta-expansion >=20 > # let g =3D (fun x -> x) (fun x -> x);; > val g : '_a -> '_a =3D > # let g x =3D (fun x -> x) (fun x -> x) x;; > val g : 'a -> 'a =3D >=20 > Polymorphism annotation ( : 'a . 'a -> 'a ) have no use here, as you can = easily see in the return type if the value is polymorphic (type variables '= a, implicitly quantified at the beginning of the type) or not ("weak" type = variable '_a, which are just unknowns waiting to be unified). >=20 > On Sun, Aug 14, 2011 at 3:46 PM, Ruslan Ledesma Garza wrote: > Dear list, >=20 > Consider the following OCaml session. >=20 > Objective Caml version 3.12.0 >=20 > # let f : 'v . 'v -> 'v =3D fun x -> x;; > val f : 'a -> 'a =3D > # let g : 'v . 'v -> 'v =3D (fun x -> x) (fun x -> x);; > Error: This definition has type 'a -> 'a which is less general than > 'b. 'b -> 'b > # >=20 > Why doesn't OCaml generalize the type 'a -> 'a? According to the typing r= ules in "Principal type-schemes for functional programs" ( http://portal.ac= m.org/citation.cfm?id=3D582176 ), the type 'a -> 'a can be generalized. >=20 > Something similar happens in the following OCaml session. >=20 > Objective Caml version 3.12.0 >=20 > # let f : 'v . 'v -> 'v =3D fun x -> x;; > val f : 'a -> 'a =3D > # let h =3D f f;; > val h : '_a -> '_a =3D > # h 1;; > - : int =3D 1 > # h h;; > Error: This expression has type int -> int > but an expression was expected of type int > # >=20 > I want the type of h to be \forall 'a . 'a -> 'a. :'( >=20 > Best regards, > Rusl=E1n. >=20 >=20 >=20 >=20 > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs >=20 >=20 --Apple-Mail-3-15940969 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=iso-8859-1 I'm so happy now. :D =

Thanks a lot!
Rusl=E1n.

On Aug 14, 2011, at 3:55 PM, Gabriel Scherer wrote:

You have hit the "value = restriction":
  http://caml.inria.fr/resources/doc/faq/core.en.h= tml#eta-expansion

# let g =3D (fun x -> x) (fun x -> x);;<= br> val g : '_a -> '_a =3D <fun>
# let g x =3D (fun x -> x) (fun= x -> x) x;;
val g : 'a -> 'a =3D <fun>

Polymorphism = annotation ( : 'a . 'a -> 'a ) have no use here, as you can easily see i= n the return type if the value is polymorphic (type variables 'a, implicitl= y quantified at the beginning of the type) or not ("weak" type variable '_a= , which are just unknowns waiting to be unified).

On Sun, Aug 14, 2011 at 3:46 PM, Ruslan Lede= sma Garza <ruslanledesmagarza@gmail.com> wrote:
Dear list,

Consider the following OCaml session.

       Objective Caml version 3.12.0

# let f : 'v . 'v -> 'v =3D fun x -> x;;
val f : 'a -> 'a =3D <fun>
# let g : 'v . 'v -> 'v =3D (fun x -> x) (fun x -> x);;
Error: This definition has type 'a -> 'a which is less general than
        'b. 'b -> 'b
#

Why doesn't OCaml generalize the type 'a -> 'a? According to the typing = rules in "Principal type-schemes for functional programs" ( http://portal= .acm.org/citation.cfm?id=3D582176 ), the type 'a -> 'a can be genera= lized.

Something similar happens in the following OCaml session.

       Objective Caml version 3.12.0

# let f : 'v . 'v -> 'v =3D fun x -> x;;
val f : 'a -> 'a =3D <fun>
# let h =3D f f;;
val h : '_a -> '_a =3D <fun>
# h 1;;
- : int =3D 1
# h h;;
Error: This expression has type int -> int
      but an expression was expected of type int
#

I want the type of h to be \forall 'a . 'a -> 'a.       &= nbsp; :'(

Best regards,
Rusl=E1n.




--
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



= --Apple-Mail-3-15940969--