caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Martin Koch <mak@issuu.com>
To: Mihamina Rakotomandimby <mihamina@rktmb.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] polymorphism in general
Date: Fri, 23 Dec 2011 11:07:35 +0100	[thread overview]
Message-ID: <CACyk+CLz1SUo9QqAK+3id2A7J9VyR=aWBaAnZXFLiiYNPbdK8Q@mail.gmail.com> (raw)
In-Reply-To: <4EF43C29.9090409@rktmb.org>

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

A function is polymorphic if it accepts _arguments_ with different types
(the return value is not considered). Thus

# let f x = x + 1;;
val f : int -> int = <fun>

is not polymorphic; it only accepts an integer.

Your function, on the other hand, is polymorphic. It accepts a two-tuple,
where any type may appear on either position, e.g.

# let f (a,b) = "hi there";;
val f : 'a * 'b -> string = <fun>

So I can use f on both, say a string and a bool pair, or an int and an
empty list.

# f("Blue Stilton", false);;
- : string = "hi there"
# f(42, []);;
- : string = "hi there"

/Martin

On Fri, Dec 23, 2011 at 9:30 AM, Mihamina Rakotomandimby <mihamina@rktmb.org
> wrote:

> Hello,
>
> I have a question about polymorphism in general.
>
> Let's take this example:
>  val polymorph1 : 'a * 'b -> string = <fun>
>
> Is it polymorph?
> I have a doubt because the result is always a "string", not something
> related to either "'a" or "'b".
>
> So another way to ask the question: is polymorphism only qualified by the
> parameter?
>
> Thank you for your help.
>
> --
> RMA.
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/**wws/info/caml-list<https://sympa-roc.inria.fr/wws/info/caml-list>
> Beginner's list: http://groups.yahoo.com/group/**ocaml_beginners<http://groups.yahoo.com/group/ocaml_beginners>
> Bug reports: http://caml.inria.fr/bin/caml-**bugs<http://caml.inria.fr/bin/caml-bugs>
>
>

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

  reply	other threads:[~2011-12-23 10:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-23  8:30 Mihamina Rakotomandimby
2011-12-23 10:07 ` Martin Koch [this message]
2011-12-27  7:44   ` David Baelde

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='CACyk+CLz1SUo9QqAK+3id2A7J9VyR=aWBaAnZXFLiiYNPbdK8Q@mail.gmail.com' \
    --to=mak@issuu.com \
    --cc=caml-list@inria.fr \
    --cc=mihamina@rktmb.org \
    /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).