<?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/398e682363175b0a71bf952390df0eae"
  from="chris.danx &lt;chris.danx@n...&gt;"
  author="chris.danx"
  date="2003-11-17T19:32:44"
  subject="[Caml-list] Closure &amp; Ref"
  prev="2003/11/61d4387625276e01c033f4a55e71b3ab"
  next="2003/11/d708e5671623d9731257696b418a4325"
  next-in-thread="2003/11/32f0890d60db507d62ab7a73dcdc1e62"
  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>
Hi,

I was toying with ocaml just now and have successfully written a 
function that takes and int that produces a function that takes an int 
to add to the original.

let prodAdd x =
    let value = ref x in
       fun y -&gt; !value + y;;

Now I want to do a function that takes a ref to a list and returns a 
function that adds items to the list and produce a function that returns 
another that returns the list.  How do I do that?

let prod_list_acc a =
   fun x -&gt; a := x :: !a; true;;

let return_acc a =
   fun () -&gt; !a;;

but that gives a "unit -&gt; int list" =.  How do you get a copy of the 
list values?


This might seem like a crazy thing to do but I am toying with an idea 
relating to a paper I read on traits.  Instead of having classes at all 
you can just have traits, closures and mutable values.


Cheers,
Chris

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

