data List: | link(first,rest) | empty() end let mt = empty() data Option: | some(v) | none() end def singles(lst, to_replace): match to_replace: | some(v) => match lst: | link(f,r) => if f == v: singles(r, to_replace) else: link(f, singles(r, some(f))) end | empty() => empty() end | none() => match lst: | link(f,r) => link(f, singles(r, some(f))) | empty() => empty() end end end let one_through_four = link(1,link(2,link(3,link(4,mt)))) let with_dups1 = link(1,link(1,link(2,link(2,link(3,link(4,mt)))))) let with_dups2 = link(1,link(2,link(3,link(3,link(3,link(4,mt)))))) singles(mt, none()) == mt singles(one_through_four, none()) == one_through_four singles(with_dups1, none()) == one_through_four singles(with_dups2, none()) == one_through_four