Fibonacci numbers in Standard ML
Example for versions
SML/NJ 110
This example uses straightforward recursive solution. The print
function prints strings. The ^
operator concatenates strings. The Int.toString
function converts integers into strings.
fun fibonacci n =
if n < 3 then
1
else
fibonacci (n-1) + fibonacci (n-2)
fun aux n =
if n > 16 then
print "\n"
else (
print (Int.toString (fibonacci n) ^ ", ");
aux (n + 1)
);
aux 1;
Comments
]]>blog comments powered by Disqus
]]>