Q:

Haskell: effective computation of recursively-defined function values

I want to compute the recursively-defined function values r(i,j), which are defined by
r i j  | i<0 || j<0   = 0
       | i==0 && j==0 = 1
       | otherwise    = (i-1) * r (i-2) j + r (i-1) (j-1)

Obviously, the NxN table of these coefficients can be computed in O(N^2). 
Unfortunately, the straightforward evaluation, like
[[r i j | j <-[0..50]]| i <- [0..50]]

is performed in screamingly ineffective way (exponential complexity).  Apparently, Haskell builds the entire recursion tree for each r i j and ignores the values of previously computed r (i-1) (j-1) etc. 
What is the elegant and effective way to compute such a table? 

A:

As FUZxxl says, this is a memoisation question. 
r i j | i < 0 || j < 0 = 0
      | otherwise      = rss !!  i !!  j

rss = [[r' i j | j <- [0..]] | i <- [0..]]
  where r' 0 0 = 1
        r' i j = (i-1) * r (i-2) j + r (i-1) (j-1)

If you need an explicit table of precisely the values up to 50, you can use take 51 (map (take 51) rss), or [[r i j | j <-[0..50]]| i <- [0..50]] as you mentioned.  Otherwise you can just call r or reference rss directly.