Re: last item. no output

"Roelof Wobben [email protected] [ocaml_beginners]" <[email protected]>
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <[email protected]>
Sébastien Dailly
[email protected] [ocaml_beginners] schreef op
18-10-2014 13:22:

Le 18/10/2014 11:21, Roelof Wobben [email protected] [ocaml_beginners] a
écrit :

Hello,

I try to solve the first challenge from the 99 ocaml problems where I
have to find the last item in a list.

So I have this :

let rec last list =
match list with
| [] -> []
| [x] -> x
| hd :: tl -> last tl
;;

I saved it into a file called test.ml and build it with corebuild
test,native.
But when I do ,/test.native [] or ./test.native [1] I see total no output.

Hello,

I think your are confusing 2 things :

- arguments in a function
- arguments in a program

When you do ./test.native [] you give the string « [] » to the ocaml
program. This is not automagicaly passed to the function « last ».

Actualy, your program has a function which is never called…

Hope this help,

Oke,

I think your remark has to do with this problem :

last [1] ;;                                                                                                                                                                           Â

Error: This expression has type int but an expression was expected of type                                                                                                              Â

         'a list                                                                                                                                                                       Â

__._,_.___

----------

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=X3oDMTJkZnNxajl1BF9TAzk3NDc2NTkwBGdycElkAzQ5OTkxOTQEZ3Jwc3BJZAMxNzA1MDA2NzY0BHNlYwNmdHIEc2xrA2dmcARzdGltZQMxNDEzNjMxODA0

• 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.