From: Remi VANICAT <vanicat@labri.u-bordeaux.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Simple question
Date: 12 Apr 2002 18:59:32 +0200 [thread overview]
Message-ID: <87k7rcn98r.dlv@wanadoo.fr> (raw)
In-Reply-To: <20020412164400.60556.qmail@web13002.mail.yahoo.com>
Eric Merritt <cyberlync@yahoo.com> writes:
> let me start off by saying that if this is not the
> place to post this type of question please direct me
> to the correct list/group. I am picking up ocaml,
> starting off by doing a few simple things. I am at
> somewhat of an impass here in that I cannot figure out
> why the function below gives me type errors. It works
> fine if I leave it non-tail recursive, but as soon as
> I put in an accumulator and make it tail-recursive it
> fails to compile. If one of you could please point me
> in the right direction for solving this problem that
> would be great. btw this is only for my own
> edification.
>
> let rec apply_fun_list x f_list accm =
> match f_list with
> h::t ->
> apply_fun_list x t accum::(h x)
> | [] ->
> accum::[];;
:: is the constructor that add something at the beginning of the
list.
so you may want to say :
let rec apply_rev_fun_list x f_list accum =
match f_list with
| h::t ->
apply_fun_list x t (h t)::accum
| [] -> accum
but there, the function will reverse the list. It might not be what
you want (but List.rev is tail recursive)
by the way, I would have wrote it like :
let rec apply_fun_list x f_list =
List.map (fun h -> h x) f_list
but List.map is not tail recursive....
--
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
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:[~2002-04-12 16:59 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-12 15:51 [Caml-list] Applications written in O'Caml Vincent Foley
2002-04-12 16:15 ` Benjamin C. Pierce
2002-04-12 16:44 ` [Caml-list] Simple question Eric Merritt
2002-04-12 16:59 ` Remi VANICAT [this message]
2002-04-12 17:04 ` Maxence Guesdon
2002-04-12 17:57 ` Remi VANICAT
2002-04-12 19:15 ` Eric Merritt
2002-04-12 19:55 ` John Prevost
2002-04-15 20:08 ` Eric Merritt
2002-04-12 20:20 ` james woodyatt
2002-04-13 11:10 ` Remi VANICAT
2002-04-13 12:45 ` [Caml-list] Applications written in O'Caml Oliver Bandel
2002-04-13 19:07 ` Benjamin C. Pierce
2002-04-12 16:40 ` Maxence Guesdon
2002-04-12 17:04 ` Warp
2002-04-13 2:27 ` eijiro_sumii
2002-04-13 3:28 ` Michael Vanier
2002-04-15 8:16 ` Nicolas barnier
2002-04-16 10:12 ` Jacek Chrzaszcz
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=87k7rcn98r.dlv@wanadoo.fr \
--to=vanicat@labri.u-bordeaux.fr \
--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