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 pBNA7flW003736 for ; Fri, 23 Dec 2011 11:07:41 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ak8CAPhR9E5KfVK2i2dsb2JhbABEm2mIHAGIKAgiAQEBCgsLBxIGIYFyAQEBAwESAhNHCwULCwQHGiEiEgEFAQoSBhMSEIdYCJoqCpxmg32IEgSCWpIojX09gkyBLw X-IronPort-AV: E=Sophos;i="4.71,398,1320620400"; d="scan'208";a="136587787" Received: from mail-we0-f182.google.com ([74.125.82.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 23 Dec 2011 11:07:35 +0100 Received: by werb13 with SMTP id b13so7235074wer.27 for ; Fri, 23 Dec 2011 02:07:35 -0800 (PST) MIME-Version: 1.0 Received: by 10.216.136.155 with SMTP id w27mr9990784wei.8.1324634855512; Fri, 23 Dec 2011 02:07:35 -0800 (PST) Received: by 10.180.97.201 with HTTP; Fri, 23 Dec 2011 02:07:35 -0800 (PST) In-Reply-To: <4EF43C29.9090409@rktmb.org> References: <4EF43C29.9090409@rktmb.org> Date: Fri, 23 Dec 2011 11:07:35 +0100 Message-ID: From: Martin Koch To: Mihamina Rakotomandimby Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary=0016e6d99c230519c304b4bf96e5 Subject: Re: [Caml-list] polymorphism in general --0016e6d99c230519c304b4bf96e5 Content-Type: text/plain; charset=ISO-8859-1 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 = 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 = 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 wrote: > Hello, > > I have a question about polymorphism in general. > > Let's take this example: > val polymorph1 : 'a * 'b -> string = > > 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 > Beginner's list: http://groups.yahoo.com/group/**ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-**bugs > > --0016e6d99c230519c304b4bf96e5 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable A function is polymorphic if it accepts _arguments_ with different types (t= he return value is not considered). Thus

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

is not polymorphic; it only accepts an integer.

<= div> Your function, on the other hand, is polymorphic. It accepts a two-tuple, w= here any type may appear on either position, e.g.=A0

# let f (a,b) =3D "hi there";;
val f : 'a * 'b -> string =3D <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 =3D "hi there"
# f(42, []);;
- : string =3D "hi there"

/Martin=A0

--0016e6d99c230519c304b4bf96e5--