From: Issac Trotts <ijtrotts@ucdavis.edu>
To: OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] @, List.append, and tail recursion
Date: Fri, 31 Jan 2003 13:34:56 -0800 [thread overview]
Message-ID: <20030131213456.GA3037@beech> (raw)
In-Reply-To: <Pine.A41.4.44.0301311705230.4055078-100000@ibm1.cicrp.jussieu.fr>
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
next prev parent reply other threads:[~2003-01-31 21:30 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-24 0:48 Brian Hurt
2003-01-30 18:10 ` Olivier Andrieu
2003-01-30 19:46 ` Brian Hurt
2003-01-30 20:52 ` Olivier Andrieu
2003-01-30 21:57 ` Brian Hurt
2003-01-31 2:16 ` james woodyatt
2003-01-31 17:05 ` Diego Olivier Fernandez Pons
2003-01-31 19:52 ` Brian Hurt
2003-02-01 10:18 ` Linear systems (was Re: [Caml-list] @, List.append, and tail recursion) Diego Olivier Fernandez Pons
2003-01-31 21:34 ` Issac Trotts [this message]
2003-01-31 17:13 ` [Caml-list] @, List.append, and tail recursion Brian Hurt
2003-01-31 17:42 ` brogoff
2003-01-31 19:18 ` Russ Ross
2003-01-31 19:32 ` Alexander V. Voinov
2003-02-01 2:30 ` brogoff
2003-01-31 23:12 ` Issac Trotts
2003-01-24 15:35 Andrew Kennedy
2003-01-30 1:44 ` brogoff
2003-01-30 9:57 ` Christophe Raffalli
2003-01-30 16:03 ` Brian Hurt
2003-01-31 10:33 ` Mattias Waldau
2003-01-31 17:32 Diego Olivier Fernandez Pons
2003-01-31 19:58 Harrison, John R
2003-01-31 21:04 ` Brian Hurt
2003-01-31 22:27 Harrison, John R
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030131213456.GA3037@beech \
--to=ijtrotts@ucdavis.edu \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox