What is the easiest way to add an element to the end of the list?
As :: : 'a -> 'a list -> 'a list is used to add an element to the begin of a list, Could anyone tell me if there is a function to add an element to the end of a list? If not, I guess List.rev (element::(List.rev list)) is the most straightforward way to do it? Thank you! Adi list@[element] should work. @ joins lists. The reason there's not a standard function to do this is that appending at the end of a list is an anti-pattern (aka a "snoc list" or a Schlemiel the Painter algorithm ). Adding an element at the end of a list requires a full copy of the list. Adding an element at the front of the