let rec replace elem list = function | head::tail -> if head=elem then list@(replace elem list tail) else head::(replace elem list tail) | [] -> []