Jump to content

Parametric polymorphism: Difference between revisions

Line 857:
(50.0, 60.0, 70.0)
</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}}==
1,111

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.