recursion with functional programing