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 WAA28137; Mon, 17 Nov 2003 22:30:04 +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 WAA28613 for ; Mon, 17 Nov 2003 22:30:03 +0100 (MET) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from mta07-svc.ntlworld.com (mta07-svc.ntlworld.com [62.253.162.47]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hAHLU2124897 for ; Mon, 17 Nov 2003 22:30:02 +0100 (MET) Received: from ntlworld.com ([80.4.69.207]) by mta07-svc.ntlworld.com (InterMail vM.4.01.03.37 201-229-121-137-20020806) with ESMTP id <20031117212958.IVOA9231.mta07-svc.ntlworld.com@ntlworld.com>; Mon, 17 Nov 2003 21:29:58 +0000 Message-ID: <3FB93F0E.2070501@ntlworld.com> Date: Mon, 17 Nov 2003 21:35:10 +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: Brian Hurt CC: caml-list@inria.fr Subject: Re: [Caml-list] Closure & Ref References: In-Reply-To: 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 caml-list:01 haskell:01 haskell:01 generic:01 generics:01 generics:01 guis:01 hash:01 chris:01 chris:01 ints:01 ocaml:01 ocaml:01 closure:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Brian Hurt wrote: > Since you're not setting the reference, why have one? Instead, try: > > let prodAdd x = fun y -> x + y > > But we can do it simpler than that: > > let prodAdd x y = x + y > > And use partial function application. (prodAdd 4) returns a function > 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). > This allows you to have multiple different lists being constructed > independently. Note, the above code is actually more generic than it > looks- I had to add an explicit type statement to make it "come out > correct". Without the explicit type information: > > let make_listacc () = > let r = ref [] in > let acc x = r := x :: !r > and lst () = !r > in acc, lst > ;; > > The function is both clearer than the original, and creates lists of any > type, not just ints. If you hear me bitching about C++ and Java making > generics "special and extraordinary", this is a classic example of what > 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] > If you want to access specific members of a list (other than the head), I > wouldn't recommend using a list, but instead some other datastructure (an > 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