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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id DC4D77ED7A for ; Thu, 6 Sep 2012 12:00:02 +0200 (CEST) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.210.182; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.210.182 as permitted sender) identity=mailfrom; client-ip=209.85.210.182; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-iy0-f182.google.com) identity=helo; client-ip=209.85.210.182; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-iy0-f182.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ai0CACxzSFDRVdK2m2dsb2JhbABFqT6RWQgiAQEBAQEICQsJFCeCIAEBAQQSAhMZARsSCwEDDAYFCwMKDSEhAQERAQUBChIGExIQh1sBAwwLnAQJA4wjgnOFFgoZJwMCCFmIdAEFDIoiYxqGKwOUBYFUgRSJfoMqPoQFgV8 X-IronPort-AV: E=Sophos;i="4.80,379,1344204000"; d="scan'208";a="172100335" Received: from mail-iy0-f182.google.com ([209.85.210.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 06 Sep 2012 12:00:02 +0200 Received: by iayy25 with SMTP id y25so3203970iay.27 for ; Thu, 06 Sep 2012 03:00:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=MyGCrEX+mDlfJEbQ2j820PYYb1wDs/qvIEiUfSEIKBg=; b=wg7oIZt/P6EtOkddRr3Z1JJfzsBXVYiqapcgJVT7247ww0me9PG27lZYQ2Z3kAh2ig 6fVw03Pn0rxEBpzFf933GZv31MnpPNoZc/b8daYZTQtXeJ2p5fyXgaeUPK2tsMRQivra eifZbP3V4MrGU5mjyiZtyWwhjZE+42PR1KNrXFG2ZAULrSvrjUIGLMLdP9G02xi44q64 HY9MBgnKY7lgzAY6grb+WGFc9uzplBSjiKLHtlewGe+PbPynTSf2HUtSAo4r82WmKjj1 nz+U7BCkJn1AnI7QY5VgNdabcj8gDP2ggvF8BfSatoju5IDw9ZU/xG+996TxMx0FSje3 vvzw== Received: by 10.43.9.3 with SMTP id ou3mr1577815icb.14.1346925600703; Thu, 06 Sep 2012 03:00:00 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.32.39 with HTTP; Thu, 6 Sep 2012 02:59:20 -0700 (PDT) In-Reply-To: References: <1346923259.77614.YahooMailRC@web180012.mail.gq1.yahoo.com> From: Gabriel Scherer Date: Thu, 6 Sep 2012 11:59:20 +0200 Message-ID: To: Philippe Wang Cc: Dan Bensen , caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [Caml-list] polymorphic parameters PS: the use of the wording "syntactic sugar" here is inappropriate: "forall 'a ..." is not valid OCaml syntax. I meant that the formal type this notation is referring to is quantified in this way. For concrete syntax to denote polymorphism, ('a . foo) is used by polymorphic field and methods or polymorphic recursion, and the blog post David House linked discusses another syntax -- and there is yet something different, a fusion of these two, for GADTs; unfortunately this aspect of OCaml syntax is getting a bit crowded. On Thu, Sep 6, 2012 at 11:55 AM, Gabriel Scherer wrote: > Philippe, the function parameter is not really polymorphic in your > example: it's the whole function type that is. > `f` is given the type (('a -> 'b) -> 'a -> 'b) by the OCaml > type-checker, but this is syntactic sugar for (forall 'a 'b. ('a -> > 'b) -> 'a -> 'b). > > Note how the universal quantifiers are at the beginning of the type, > and not inside the function parameter. > One could expect to be able to express the type forall 'a . (forall 'b > . 'a -> 'b) -> 'a -> int for example. > > See the following FAQ item for a short answer to this question: > http://caml.inria.fr/resources/doc/faq/core.en.html#polymorphic-arguments > > On Thu, Sep 6, 2012 at 11:35 AM, Philippe Wang wrote: >> On Thu, Sep 6, 2012 at 11:20 AM, Dan Bensen wrote: >>> How do you indicate that a function parameter is a polymorphic function? >> >> I hope these 2 lines will answer your question: >> >> let f g x = g x >> >> let f (g: 'a -> 'b) x = g x >> >> -- >> Philippe Wang >> mail@philippewang.info >> >> -- >> 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 >>