English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Reporting on sucess/failure of tail recursion
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-12-02 (10:16)
From: Erik de Castro Lopo <ocaml-erikd@m...>
Subject: Re: [Caml-list] Reporting on sucess/failure of tail recursion
basile@starynkevitch.net wrote:

> Functions are not tail-recursive, but function *calls* are (or not)
> tail-recursive. I mean that a given function may have both tail
> [-recursive]
> and non-tail [-recursive] calls.

Ok, so many recursive functions are actually written like:

    let fact n =
        let rec sub_fact curr acc =
            if curr > n then acc
            else sub_fact (curr + 1) (curr * acc)
        sub_fact 1 1

with a no-recursive outer function and a tail recursive inner function.
It would still be nice to know if the inner function is tail recursive.
> Maybe what you are dreaming of is an extension of the -dtypes flag (to
> ocamlc)

Ooo, I didn't know about -dtypes. That might be useful. Thanks.

Yes, something like -dtypes.

  Erik de Castro Lopo
"That being done, all you have to do next is call free() slightly 
less often than malloc(). You may want to examine the Solaris 
system libraries for a particularly ambitious implementation of 
this technique."
-- Eric O'Dell (comp.lang.dylan)