<?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="2003/11/46312cc55957d6ec48f8b0439fb04d84"
  from="chris.danx &lt;chris.danx@n...&gt;"
  author="chris.danx"
  date="2003-11-17T21:30:04"
  subject="Re: [Caml-list] Closure &amp; Ref"
  prev="2003/11/41e94f145d604f09aacb6c4947bc279a"
  next="2003/11/5f963c7ed269cdd4ed0e0979ee211090"
  prev-in-thread="2003/11/32f0890d60db507d62ab7a73dcdc1e62"
  next-in-thread="2003/11/c62502b67c01192d18d301d00e9d2b31"
  prev-thread="2003/11/496b39537f731229ef7c3864e45156c0"
  next-thread="2003/11/4d893cc52b22fe3904f8f579fcf78b2d"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Closure &amp; Ref">
<msg 
  url="2003/11/398e682363175b0a71bf952390df0eae"
  from="chris.danx &lt;chris.danx@n...&gt;"
  author="chris.danx"
  date="2003-11-17T19:32:44"
  subject="[Caml-list] Closure &amp; Ref">
<msg 
  url="2003/11/32f0890d60db507d62ab7a73dcdc1e62"
  from="Brian Hurt &lt;bhurt@s...&gt;"
  author="Brian Hurt"
  date="2003-11-17T20:44:47"
  subject="Re: [Caml-list] Closure &amp; Ref">
<msg 
  url="2003/11/46312cc55957d6ec48f8b0439fb04d84"
  from="chris.danx &lt;chris.danx@n...&gt;"
  author="chris.danx"
  date="2003-11-17T21:30:04"
  subject="Re: [Caml-list] Closure &amp; Ref">
</msg>
</msg>
<msg 
  url="2003/11/c62502b67c01192d18d301d00e9d2b31"
  from="Dustin Sallings &lt;dustin@s...&gt;"
  author="Dustin Sallings"
  date="2003-11-17T21:02:39"
  subject="Re: [Caml-list] Closure &amp; Ref">
<msg 
  url="2003/11/5f963c7ed269cdd4ed0e0979ee211090"
  from="Dustin Sallings &lt;dustin@s...&gt;"
  author="Dustin Sallings"
  date="2003-11-17T21:48:23"
  subject="Re: [Caml-list] Closure &amp; Ref">
</msg>
</msg>
</msg>
</thread>

<contents>
Brian Hurt wrote:

&gt; Since you're not setting the reference, why have one?  Instead, try:
&gt; 
&gt; let prodAdd x = fun y -&gt; x + y
&gt; 
&gt; But we can do it simpler than that:
&gt; 
&gt; let prodAdd x y = x + y
&gt; 
&gt; And use partial function application.  (prodAdd 4) returns a function 
&gt; which adds 4 to whatever int parameter passed to it.

I didn't know OCaml had partial function application, thanks!  I have 
programmed in Haskell before, but never got seriously into it (the 
things I wanted to do like IO where "advanced" in Haskell, whereas 
they're basic to me.  That's one reason I want to learn OCaml, it 
doesn't so hard to do trivial interaction).


&gt; This allows you to have multiple different lists being constructed 
&gt; independently.  Note, the above code is actually more generic than it 
&gt; looks- I had to add an explicit type statement to make it "come out 
&gt; correct".  Without the explicit type information:
&gt; 
&gt; let make_listacc () =
&gt;         let r = ref [] in
&gt;         let acc x = r := x :: !r
&gt;         and lst () = !r
&gt;         in acc, lst
&gt; ;;
&gt; 
&gt; The function is both clearer than the original, and creates lists of any 
&gt; type, not just ints.  If you hear me bitching about C++ and Java making 
&gt; generics "special and extraordinary", this is a classic example of what 
&gt; I'm kvetching about.

I hear you.  From my previous spell in FP I really got to like the ease 
of "generics" which are inconvient in C++ and a pain in Ada.  GUIs and 
IO was just easier.

[snip]

&gt; If you want to access specific members of a list (other than the head), I
&gt; wouldn't recommend using a list, but instead some other datastructure (an
&gt; array or hash table being the obvious choices).

It was just a toy example to see if I could get that aspect of this idea 
to work in OCaml.  Hmm...

Thanks!

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

