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
my stupidity and non-tail calls
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1999-12-15 (21:15)
From: Daniel de Rauglaudre <daniel.de_rauglaudre@i...>
Subject: Re: my stupidity and non-tail calls
> OK, I apologize for bothering everyone.  My `tail calls' are actually
> sitting inside `try ... with' blocks, so I recognize that these cannot be
> optimized since they are in the scope of different handlers.  I will
> have to find a way to restructure my code.  A great pity, since
> I like it the way it is... suggestions are welcome.

To resolve this problem, instead of:

       let x = exp in
       f x
     with Exception -> y

you can use the equivalent (but the call to "f" is tail):

      match (try Some exp with Exception -> None) with
        Some x -> f x
      | None -> y

I use that thousands of times in my code, when needed.