Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Re: [Caml-list] Applications written in O'Caml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Remi VANICAT <vanicat@l...>
Subject: Re: [Caml-list] Simple question
Eric Merritt <> 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

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 = (fun h -> h x) f_list

but is not tail recursive....

Rémi Vanicat
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: