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 WAA04042; Fri, 31 Jan 2003 22:30:38 +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 WAA03993 for ; Fri, 31 Jan 2003 22:30:37 +0100 (MET) Received: from pop9.ucdavis.edu (pop9.ucdavis.edu [169.237.105.19]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h0VLUZf17133 for ; Fri, 31 Jan 2003 22:30:36 +0100 (MET) Received: from beech ([128.120.141.217]) by pop9.ucdavis.edu (8.11.6/8.11.0/IT4.6.2) with ESMTP id h0VLUXa29400 for ; Fri, 31 Jan 2003 13:30:33 -0800 (PST) Received: from ijtrotts by beech with local (Exim 3.36 #1 (Debian)) id 18eioK-0000oa-00 for ; Fri, 31 Jan 2003 13:34:56 -0800 Date: Fri, 31 Jan 2003 13:34:56 -0800 To: OCaml Mailing List Subject: Re: [Caml-list] @, List.append, and tail recursion Message-ID: <20030131213456.GA3037@beech> References: <11707E79-34C2-11D7-9ECD-000393BA7EBA@wetware.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4i From: Issac Trotts Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Fri, Jan 31, 2003 at 06:05:30PM +0100, Diego Olivier Fernandez Pons wrote: > Bonjour, > > Some comments on various contributions to this thread > > Brian Hurt wrote : > > > I'm basically doing sparse vector/matrix stuff, handling > > (effectively) (colno * value) list for vectors, and (rowno * vector) > > list for matrix. And I may be hitting lists long enough to trip the > > problem. > > If you are doing sparse matrix operations and you still hit lists long > enough to cause a stack overflow, then your matrix must be really > huge. > > If the ordrer of the terms does not matter (or if you can manage with > the position information you keep in your sparse matrix) then you just > need to write tail recursive functions, not taking care of the list > being reversed > > let rec rev_map f result = function > | [] -> result > | head :: tail -> rev_map (f head) tail This doesn't work on OCaml 3.06: "This expression has type 'a but is here used with type 'b -> 'a" How about let rec rev_map f result = function | [] -> result | head :: tail -> rev_map f (f head :: result) tail;; # map ((+) 3) [] [1;2;3;4;5];; - : int list = [8; 7; 6; 5; 4] Issac [snip] -- ------------------- 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