let valid  piece =

  if piece = 'r' then r f x y else
  if piece = 'b' then b f x y else false