<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/12/3a29f1975beda5e8c692774800ed0d87"
  from="Pierre Weis &lt;pierre.weis@i...&gt;"
  author="Pierre Weis"
  date="2002-12-05T10:01:05"
  subject="Re: [Caml-list] function"
  prev="2002/12/3e71211f2fb2f80fd9a238faabbe7baa"
  next="2002/12/ab87b0205aa5dcf4eb05a70cbca50974"
  prev-in-thread="2002/12/9b00251c6816fbc02c4a06d09719d33e"
  next-in-thread="2002/12/019830184ea14462c3df69900b5a0cda"
  prev-thread="2002/12/e69ce402ec37766285461eb0c4583d17"
  next-thread="2002/12/838549db9eab58c179d31f32eefdf381"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] function">
<msg 
  url="2002/12/67f44329195eaf652b43093fd3ca01ba"
  from="altavillasalvatore@libero.it &lt;altavillasalvatore@l...&gt;"
  author="altavillasalvatore@libero.it"
  date="2002-12-02T15:55:08"
  subject="[Caml-list] function">
<msg 
  url="2002/12/aa10f5e9e0a36a35e6d25918c9404768"
  from="sebastien FURIC &lt;sebastien.furic@t...&gt;"
  author="sebastien FURIC"
  date="2002-12-02T16:30:12"
  subject="Re: [Caml-list] function">
</msg>
<msg 
  url="2002/12/01b22e6f3b5a5470860e77cba7c48d8e"
  from="Oleg &lt;oleg_inconnu@m...&gt;"
  author="Oleg"
  date="2002-12-02T17:35:49"
  subject="Re: [Caml-list] function">
</msg>
<msg 
  url="2002/12/9b00251c6816fbc02c4a06d09719d33e"
  from="Issac Trotts &lt;ijtrotts@u...&gt;"
  author="Issac Trotts"
  date="2002-12-03T23:21:13"
  subject="Re: [Caml-list] function">
<msg 
  url="2002/12/3a29f1975beda5e8c692774800ed0d87"
  from="Pierre Weis &lt;pierre.weis@i...&gt;"
  author="Pierre Weis"
  date="2002-12-05T10:01:05"
  subject="Re: [Caml-list] function">
<msg 
  url="2002/12/019830184ea14462c3df69900b5a0cda"
  from="Issac Trotts &lt;ijtrotts@u...&gt;"
  author="Issac Trotts"
  date="2002-12-05T20:24:25"
  subject="Re: [Caml-list] function">
<msg 
  url="2002/12/6a861191e568645e8947da7ef9a991bc"
  from="Oleg &lt;oleg_inconnu@m...&gt;"
  author="Oleg"
  date="2002-12-05T23:01:21"
  subject="Re: [Caml-list] function">
<msg 
  url="2002/12/5581c0bd84fc85a1433cc7954b60ed48"
  from="Issac Trotts &lt;ijtrotts@u...&gt;"
  author="Issac Trotts"
  date="2002-12-06T21:30:52"
  subject="Re: [Caml-list] function">
<msg 
  url="2002/12/458ac04874c1d4210349ca4aef0cefb1"
  from="Xavier Leroy &lt;xavier.leroy@i...&gt;"
  author="Xavier Leroy"
  date="2002-12-07T10:28:25"
  subject="Re: [Caml-list] function">
<msg 
  url="2002/12/938da7b77f8b3b294f4ae5d5dade6d4f"
  from="Oleg &lt;oleg_inconnu@m...&gt;"
  author="Oleg"
  date="2002-12-07T17:32:03"
  subject="Re: [Caml-list] function">
</msg>
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2002/12/ae8917859b7799193678c7a51ce64247"
  from="Oleg &lt;oleg_inconnu@m...&gt;"
  author="Oleg"
  date="2002-12-05T20:47:21"
  subject="Re: [Caml-list] function">
<msg 
  url="2002/12/87e12bef39b1bf9fc066aa51f3deb525"
  from="Pal-Kristian Engstad &lt;engstad@n...&gt;"
  author="Pal-Kristian Engstad"
  date="2002-12-05T21:04:47"
  subject="Re: [Caml-list] function">
</msg>
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>
&gt; On Mon, Dec 02, 2002 at 04:55:06PM +0100, altavillasalvatore@libero.it wrote:
&gt; &gt; Hi all,
&gt; &gt; I would want to know if a function exists that allows me to make this:
&gt; &gt; 
&gt; &gt; ["123";"45";"678"]  -&gt;  [1;2;3;4;5;6;7;8;].
&gt; 
&gt; let f l = 
&gt;   let ret = ref [] in
&gt;   String.iter 
&gt;     (fun c -&gt; ret := ((int_of_char c) - (int_of_char '0')) :: !ret) 
&gt;     (List.fold_left (^) "" l);
&gt;   List.rev !ret;;
&gt;   
&gt; f ["123";"45";"678"];;
&gt; 
&gt; Cheers,
&gt; Issac Trotts

If you like puzzles, here is an additional exercise:

00) List which parens are useless in this code, according to which
    rules given in the simple guide-lines and syntactic conventions of
    http://pauillac.inria.fr/caml/FAQ/qrg-eng.html#parens and
    http://pauillac.inria.fr/caml/FAQ/pgl-eng.html#parens.
0)  Rewrite this code to a more suitable form for a beginner,
    i.e. in a purely functional style with no side effect.
1)  Try to avoid the useless List.rev at the end.
2)  What is the complexity of your function f ?
3)  Explain why the List.fold_left application is not only over
    complex but also runtime over consuming.

Hope this helps.

Cheers,

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

</contents>

</message>

