| Newsgroups |
gmane.comp.lang.ocaml.beginners |
| Message-ID |
<[email protected]> |
Oke,
If I look it it seems to me that acc does the same as l2 on my
programm.
But does acc not have to be intialized on some way ?
Sébastien
then the outcome will be :
string list = ["c"; "b"; "a"; "1"; "2"; "3"]
so it reverse the second string and not the first one.
Roelof
Chingfan Tsao [email protected] [ocaml_beginners] schreef op
20-10-2014 15:55:
Hi,
It is indeed a good way to solve it since it's tail
recursion, however, there's one more thing to do to make
it easier, wrap it with a more convenient function:
let rev_list_tail_rec l =
let rec aux_rev l accum =
match l with
| [] -> accum
| h :: tl ->
aux_rev tl (h::accum)
in
aux_rev l []
this way, you can just use rev_list_tail_rec l
instead of having to give one more [] as the initial
value of the accumulator.
2014-10-20 18:56 GMT+08:00 Roelof
Wobben [email protected]
[ocaml_beginners] <[email protected] >:
Hello,
I try the 99 ocaml problems and have solved
the reverse a list problem.
My solution looks like this :
let rec test l1 l2 =
match l1 with
| [] -> l2
| h :: t -> test t (h::l2)
;;
Is this a good way to solve it or are there
things that can be better ?
Roelof
--
曹竞帆
哈尔滨工业大学计算机科学与技术专业本科在读
哈尔滨工业大学IBMTC成员
__._,_.___
----------
Posted by: Roelof Wobben <[email protected]>
----------
Reply via web post
•
Reply to sender
•
Reply to group
•
Start a New Topic
•
Messages in this topic
(4)
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
-
New Members
3
https://groups.yahoo.com/neo;_ylc=X3oDMTJkZWtmaXE1BF9TAzk3NDc2NTkwBGdycElkAzQ5OTkxOTQEZ3Jwc3BJZAMxNzA1MDA2NzY0BHNlYwNmdHIEc2xrA2dmcARzdGltZQMxNDEzODIwNTg4
• Privacy • Unsubscribe • Terms of Use
.
__,_._,___