Re: what did I do wrong here ?

"Matthieu Dubuget [email protected] [ocaml_beginners]" <[email protected]>
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <[email protected]>
Le 14/10/2014 18:33, Roelof Wobben [email protected] [ocaml_beginners] a 
écrit :

> let rec sum a = if a = 0 then a = a + 0 else a = a + sum (a - 1) ;; 

The two branches of your if structure are tests :

  * |a = a + 0| which is |true|
  * and |a = a + sum (a - 1)|

So. |sum| should return a |bool|, right ?

But in the same time, you are using |sum| as if it would return an int, 
since you add |sum(a - 1) to|a|with the|+` function that takes to ints 
and returns an int.

Just get rid of the |a =|: the result of the function is either the true 
branch of the if test, or the false branch.

Hoping this will help.

​

-- 
Matthieu Dubuget
Guide d’autodéfense numérique : http://guide.boum.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.