[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: functional languages ill-suited for large programs?



> Date: Fri, 31 Oct 2003 18:57:46 -0500 (EST)
> From: Alan Bawden <Alan@lcs.mit.edu>
> 
>    Cc: Vadim Nasardinov <el-vadimo@comcast.net>, ll1-discuss@ai.mit.edu
>    From: Jim Blandy <jimb@redhat.com>
>    Date: 31 Oct 2003 17:14:57 -0500
>    ...
>    That is, whether or not it's *worthwhile* to memoize a function, a
>    pure lazy language doesn't even allow me to *express* a memoized
>    function behind a purely functional interface, even though the
>    resulting behavior is purely functional.
> 
> In Haskell, this:
> 
>   fib 0 = 0
>   fib 1 = 1
>   fib n = fib (n - 1) + fib (n - 2)
> 
> is a very inefficient way to compute factorial, whereas this:

It's also a very inefficient way to compute fibonacci numbers ;-)

> 
>   fib = ((map fib' [0 ..]) !!)
>     where
>       fib' 0 = 0
>       fib' 1 = 1
>       fib' n = fib (n - 1) + fib (n - 2)
> 
> is a memoized version that executes quite quickly.  It seems to me that I
> have just expressed the notion of a memoized function in a purely
> functional language.
> 

Very nice example!  Thanks.

All-functions-are-factorials-if-you-stare-at-them-long-enough-ly y'rs,

Mike