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 <[email protected]
> 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>
>
>

-- 
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 via email to