# ML sum unification error

Page 1 of 1

## 1 Replies - 995 Views - Last Post: 23 October 2016 - 11:52 AM

### #1 notebook123

Reputation: 0
• Posts: 1
• Joined: 23-October 16

# ML sum unification error

Posted 23 October 2016 - 11:40 AM

Hi,

I am trying to carry out approximations for e:
function eapprox(n) = 1+11!+12!+⋯+1(n−1)!, in ML.

My code looks like this:

[ fun facr(0) = 1
| facr(n) = n * facr(n-1) ;

fun sumr(x:real, n)=
if n=1 then x
else x + sumr(x/real(facr(n)) , n-1);

fun eapprox(n:real) = suma(1.0 , n); ]

I get an error unifying int and real, but I don't know how to solve this in ways other than I have tried in my code.

notebook123, on 23 October 2016 - 11:38 AM, said:

Hi,

I am trying to carry out approximations for e:
function eapprox(n) = 1+11!+12!+⋯+1(n−1)!, in ML.

My code looks like this:

[ fun facr(0) = 1
| facr(n) = n * facr(n-1) ;

fun sumr(x:real, n)=
if n=1 then x
else x + sumr(x/real(facr(n)) , n-1);

fun eapprox(n:real) = suma(1.0 , n); ]

I get an error unifying int and real, but I don't know how to solve this in ways other than I have tried in my code.

sorry, should say 1+1/1!+1/2!+⋯+1/(n−1)!,

Is This A Good Question/Topic? 0

## Replies To: ML sum unification error

### #2 sepp2k

• D.I.C Lover

Reputation: 2757
• Posts: 4,419
• Joined: 21-June 11

## Re: ML sum unification error

Posted 23 October 2016 - 11:52 AM

In the future please post the complete error message, including the location info (i.e. where in the code the error happens).

It seems like your problem is that you've declared n to be an int in the definition of eapprox, but you otherwise treat it as an int: you subtract 1 from it, not 1.0, you compare it to 1 (in fact you use = on it at all) and you pass it as an argument to facr, which takes an int - though given the name, that's kind of confusing.