import qualified Data.MemoCombinators as Memo -- memoizing a function remembers all earlier computed results -- also known as Dynamic Programming a114851 = open where open = Memo.integral $ \n -> -- counts number of open lambda terms of size n if n<2 then 0 else -- no code shorter than 2 bits 1 + -- encode variable index n-1 in n bits open (n-2) + -- only count lambda terms if qLam sum [open i * open (n-2-i) | i <- [0..n-2]] -- count applications main = print . map a114851 $ [0..]