Implementation of Smallest Free Number

Adapted from Pearls of Functional Algorithm Design, Richard Bird, 2010