Hi,

I was looking at the List module and thought the len function was 
elegant, but not very fast. While the smart people are working on the 
hard stuff, these things can be improved by the rest of us.

My test programme went from 28.83 secs to 1.27 secs with this version of 
len. Go cat, go!

Cheers,
Jonathan.

//------------
fun len[T](lst:list[T]): int =
{
    fun ln[T] (acc:int, lst:list[T]) =
    {
        return
            match lst with
                | Empty => acc
                | Cons (_,?t) => ln[T] (acc + 1, t)
            endmatch;
    }
  return ln[T] (0, lst);
}
//------------

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to