Ad-hoc Functional programming in scala