fun count a [] = (0,[]) | count a (x::xs) = let val (num, lst) = count a xs; in if a = x then (num+1, lst) else (num, x::lst) end;