Beginner's question: Memo functions in Haskell

Malcolm Wallace Malcolm.Wallace@cs.york.ac.uk
Wed, 5 Jun 2002 12:17:31 +0100


"Arjan van IJzendoorn" <afie@cs.uu.nl> writes:

> There is a Memo module in Hugs, which I just used for fib. It doesn't
> seem to speed it up, though:

You need to call the memoised version in the recursive case.

> module Fib where
> 
> import Memo
> 
> slow 0 = 0
> slow 1 = 1
> slow n = slow (n-1) + slow (n-2)

  slow n = fast (n-1) + fast (n-2)

> fast n = memo slow n

Regards,
    Malcolm