Parametric polymorphism: Difference between revisions
Content added Content deleted
Line 857: | Line 857: | ||
(50.0, 60.0, 70.0) |
(50.0, 60.0, 70.0) |
||
</pre> |
</pre> |
||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
|||
The Wolfram language is naturally polymorphic. Function can (generally) accept any type. Here an example to join two lists of with different types and an example of squaring an input: |
|||
<lang Mathematica>f[a_] := Join[a, a] |
|||
f[{1, 2, 3}] |
|||
f[{"1", "2", "3"}] |
|||
f[{1.1, 2.1, 3.1}] |
|||
f[G[1, "a", Pi]] |
|||
g[x_] := x^2 |
|||
g[2] |
|||
g[3.5] |
|||
g[Pi] |
|||
g["a"]</lang> |
|||
{{out}} |
|||
<pre>{1,2,3,1,2,3} |
|||
{1,2,3,1,2,3} |
|||
{1.1,2.1,3.1,1.1,2.1,3.1} |
|||
G[1,a,\[Pi],1,a,\[Pi]] |
|||
4 |
|||
12.25 |
|||
\[Pi]^2 |
|||
(a)^2</pre> |
|||
=={{header|Mercury}}== |
=={{header|Mercury}}== |