From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA23471; Mon, 17 Nov 2003 20:32:44 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA23859 for ; Mon, 17 Nov 2003 20:32:43 +0100 (MET) Received: from mta03-svc.ntlworld.com (mta03-svc.ntlworld.com [62.253.162.43]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hAHJWb114631 for ; Mon, 17 Nov 2003 20:32:37 +0100 (MET) Received: from ntlworld.com ([80.4.69.207]) by mta03-svc.ntlworld.com (InterMail vM.4.01.03.37 201-229-121-137-20020806) with ESMTP id <20031117193237.SXBD20615.mta03-svc.ntlworld.com@ntlworld.com> for ; Mon, 17 Nov 2003 19:32:37 +0000 Message-ID: <3FB92396.4060908@ntlworld.com> Date: Mon, 17 Nov 2003 19:37:58 +0000 From: "chris.danx" User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031014 Thunderbird/0.3 X-Accept-Language: en-us, en MIME-Version: 1.0 To: caml-list@inria.fr Subject: [Caml-list] Closure & Ref Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; ntlworld:99 toying:01 toying:01 traits:01 traits:01 closures:01 chris:01 chris:01 ocaml:01 mutable:01 closure:01 int:01 int:01 unit:03 classes:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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 -> !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 -> a := x :: !a; true;; let return_acc a = fun () -> !a;; but that gives a "unit -> 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