exercises 6, 7, 8 in Scheme and Haskell