caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Philippe Wang <mail@philippewang.info>
Cc: Dan Bensen <danbensen@att.net>, caml-list@inria.fr
Subject: Re: [Caml-list] polymorphic parameters
Date: Thu, 6 Sep 2012 11:59:20 +0200	[thread overview]
Message-ID: <CAPFanBGFgQUfiG4kpvk27=qaFMGdn0hkLa0C90sULTk6j30AOg@mail.gmail.com> (raw)
In-Reply-To: <CAPFanBENEXKofW63nC6Amet6ZMeg=g4GaJ5Mzivcqy_E7WY0Sw@mail.gmail.com>

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
<gabriel.scherer@gmail.com> 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 <mail@philippewang.info> wrote:
>> On Thu, Sep 6, 2012 at 11:20 AM, Dan Bensen <danbensen@att.net> 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
>>

      reply	other threads:[~2012-09-06 10:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-06  9:20 Dan Bensen
2012-09-06  9:35 ` Philippe Wang
2012-09-06  9:49   ` David House
2012-09-06 13:19     ` Philippe Wang
2012-09-06  9:55   ` Gabriel Scherer
2012-09-06  9:59     ` Gabriel Scherer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPFanBGFgQUfiG4kpvk27=qaFMGdn0hkLa0C90sULTk6j30AOg@mail.gmail.com' \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=danbensen@att.net \
    --cc=mail@philippewang.info \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).