On 5/27/07, Stefan O'Rear <[EMAIL PROTECTED]> wrote:
memofix :: ((a -> b) -> (a -> b)) -> a -> b
memofix ff = let g = memoize (ff g) in g

fib = memofix $ \fib k -> case k of
        0 -> 0
        1 -> 1
        n -> fib (n-1) + fib (n-2)

But this way you miss pattern matching and guards? How would you write
something like:

ack = curry (memoize a) where
 a (0,n)                  = n + 1
 a (m,0)                  = ack (m-1) 1
 a (m,n) | m < 0 || n < 0 = error "ack of negative integer"
         | otherwise      = let inner = ack m (n-1)
                            in  ack (m-1) inner


--
Felipe.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to