safeSet :: Ord k => [k] -> Either k (Set k)
safeSet = foldM safeInsert Set.empty where
  safeInsert s x = if Set.member x s then Left x else Right $ Set.insert x s
safeSet :: Ord k => [k] -> Either k (Set k)
safeSet = foldM safeInsert Set.empty where
  safeInsert s x = if Set.member x s then Left x else Right $ Set.insert x s
safeSet = foldM safeInsert Set.empty where
  safeInsert s x = if Set.member x s then Left x else Right $ Set.insert x s