Re: what did I do wrong here ?

"Roelof Wobben [email protected] [ocaml_beginners]" <[email protected]>
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <[email protected]>
it helps but still im a little bit
confused.

What I try to do it this :

lets say I want to calculate this 1+2+3

then first 2+3 must be calculated and the outcome will be 5

then 5+1 must be calculated so the outcome will be 6.

Now there are no arguments anymore so the outcome must be
displayed.

But if there are no arguments so sum then the answer must be 0

and I use this as a example and here a= is used : # let rec
factorial a = if a = 1 then 1 else a * factorial (a - 1);;

Roelof

Matthieu Dubuget [email protected] [ocaml_beginners]
schreef op 14-10-2014 18:49:

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) toawith
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

__._,_.___

----------

Posted by: Roelof Wobben <[email protected]>
----------

Reply via web post

•

Reply to sender

•

Reply to group

•

Start a New Topic

•

Messages in this topic
(3)

Archives up to December 31, 2011 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners

The archives of the very official ocaml list (the seniors' one) can be found at http://caml.inria.fr

Attachments are banned and you're asked to be polite, avoid flames etc.

Visit Your Group

https://groups.yahoo.com/neo;_ylc=X3oDMTJkbzZiZHNjBF9TAzk3NDc2NTkwBGdycElkAzQ5OTkxOTQEZ3Jwc3BJZAMxNzA1MDA2NzY0BHNlYwNmdHIEc2xrA2dmcARzdGltZQMxNDEzMzA4NjQ1

• Privacy • Unsubscribe • Terms of Use

.

__,_._,___
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.