> What do you think would be the best representation of the buffer for
> such a crazy idea as a text editor in Haskell?
>
> The first choice: mutable or not. If it were pure functional, like
> GHC's FiniteMap, it would be easy to implement undo: just store
> various buffer states in a list, hoping that the underlying structure
> will share most of the unchanged state. I'm just afraid it will be
> too inefficient without a really good structure.
[...]
> Is there a better structure?
You might have a look at:
Gérard P. Huet: The Zipper.
Journal of Functional Programming 7(5): 549-554 (1997)
This data structure gives you in a purely functional setting navigation
operations for cursor movements in constant time. This is important, since
the updates are performed at the cursor position. It is applicable for
simple text-oriented editors as well as for e.g. systems with more
structured data such as a proof editor with axioms and lemmas.
To cite from the ``Capsule Review'':
[...] The Zipper is Huet's nifty name for a nifty data structure ...
Regards,
--Bernd.