caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] polymorphic parameters
@ 2012-09-06  9:20 Dan Bensen
  2012-09-06  9:35 ` Philippe Wang
  0 siblings, 1 reply; 6+ messages in thread
From: Dan Bensen @ 2012-09-06  9:20 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 73 bytes --]

How do you indicate that a function parameter is a polymorphic function?

[-- Attachment #2: Type: text/html, Size: 281 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] polymorphic parameters
  2012-09-06  9:20 [Caml-list] polymorphic parameters Dan Bensen
@ 2012-09-06  9:35 ` Philippe Wang
  2012-09-06  9:49   ` David House
  2012-09-06  9:55   ` Gabriel Scherer
  0 siblings, 2 replies; 6+ messages in thread
From: Philippe Wang @ 2012-09-06  9:35 UTC (permalink / raw)
  To: Dan Bensen; +Cc: caml-list

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] polymorphic parameters
  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
  1 sibling, 1 reply; 6+ messages in thread
From: David House @ 2012-09-06  9:49 UTC (permalink / raw)
  To: Philippe Wang; +Cc: Dan Bensen, caml-list

Careful: that doesn't actually ensure polymorphism. See:

https://ocaml.janestreet.com/?q=node/79

On Thu, Sep 6, 2012 at 10: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
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] polymorphic parameters
  2012-09-06  9:35 ` Philippe Wang
  2012-09-06  9:49   ` David House
@ 2012-09-06  9:55   ` Gabriel Scherer
  2012-09-06  9:59     ` Gabriel Scherer
  1 sibling, 1 reply; 6+ messages in thread
From: Gabriel Scherer @ 2012-09-06  9:55 UTC (permalink / raw)
  To: Philippe Wang; +Cc: Dan Bensen, caml-list

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
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] polymorphic parameters
  2012-09-06  9:55   ` Gabriel Scherer
@ 2012-09-06  9:59     ` Gabriel Scherer
  0 siblings, 0 replies; 6+ messages in thread
From: Gabriel Scherer @ 2012-09-06  9:59 UTC (permalink / raw)
  To: Philippe Wang; +Cc: Dan Bensen, caml-list

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
>>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] polymorphic parameters
  2012-09-06  9:49   ` David House
@ 2012-09-06 13:19     ` Philippe Wang
  0 siblings, 0 replies; 6+ messages in thread
From: Philippe Wang @ 2012-09-06 13:19 UTC (permalink / raw)
  To: David House; +Cc: Dan Bensen, caml-list

You're right, I misread the question!
(I missed one word, which changed the semantics of the question)

On Thu, Sep 6, 2012 at 11:49 AM, David House <dhouse@janestreet.com> wrote:
> Careful: that doesn't actually ensure polymorphism. See:
>
> https://ocaml.janestreet.com/?q=node/79
>
> On Thu, Sep 6, 2012 at 10: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
>>



-- 
Philippe Wang
   mail@philippewang.info

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-09-06 13:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-06  9:20 [Caml-list] polymorphic parameters 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 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).