Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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:

     try
       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.

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/