#!/usr/local/bin/swift
func recall<T,R>(f:((T->R),T)->R)->T->R {
   var r:(T->R)!
   r = { n in f(r,n) }
   return r
}
let fact = recall { $1 <= 1 ? 1 : $1 * $0($1-1) }
for i in (0...20) {
  print(fact(i))
}