| is there an opposite (:) available in haskell?
| like, i can toss an element at the back of a list without
| O(n) fuss recursing bla??
|
| The (:) operator is internally, isn't it? So why not make life easier
| and create (hack) an opposite of it?
The operator that you are looking for, sometimes called `snoc'
because it's like a backwards version of `cons', could, of course
be defined:
snoc xs x = xs ++ [x]
but that won't have the complexity bounds that you are looking for.
There is no simple hack that will allow you to support snoc with O(1)
complexity on standard Haskell lists ... but you could use a different
data structure, and I'd strongly recommend Chris Okasaki's paper on
simple and efficient purely functional queues and dequeues as a
starting point for this:
http://www.cs.columbia.edu/~cdo/papers.html#jfp95
All the best,
Mark