
Hello all, I have rather strange question. I wonder whether there is an obvious solution or not in Haskell. I tried but without defining quite ugly tree-like structures and incorporating IORefs it seems to me like impossible. Note: I use ASCII art to explain. let l be a Haskell list +-+-+-------------------------------------+ l = | | | .... | +-+-+-------------------------------------+ let li be another Haskell list +-+-+-+ li = |a|b|c| +-+-+-+ let hi be a hook/pointer list such, that it links some/all members of the list li +--+--+--+ hi = |pa|pb|pc| +--+--+--+ | | | V V V +--+--+--+ li = |a |b |c | +--+--+--+ When I insert li into l, I would like to get something like: +--+--+--+ hi = |pa|pb|pc| +--+--+--+ | | | V V V +-+-+----------+--+--+--+---------------------------+ l' = | | | .... |a |b |c | | +-+-+----------+--+--+--+---------------------------+ where l' is still a Haskell list. Now, I would like to modify, directly via pb the list l' to have: +--+--+--+ hi = |pa|pb|pc| +--+--+--+ | | +-------+ V V V +-+-+----------+--+--+-+-+-+-+--+---------------------------+ le = | | | .... |a |b |q|w|e|r|c | | +-+-+----------+--+--+-+-+-+-+--+---------------------------+ where le is a Haskell list, but, in fact accessible through the same ID/reference all the time. Simply: I would like to have direct access into several places in a very long list. Moreover, the efficiency and features of Haskell list and all the functions around it are to be used as well (not all, but many, nevertheless, I could make them new, if I can achieve good performance, not a big trouble). Is it possible, or not? Could you possibly point me to some resource I can get more information about such "tricks". Thanks John -- John Sneer johnsneer@operamail.com -- http://www.fastmail.fm - A no graphics, no pop-ups email service

On 2 May 2011 11:10, John Sneer
Hello all,
I have rather strange question. I wonder whether there is an obvious solution or not in Haskell. I tried but without defining quite ugly tree-like structures and incorporating IORefs it seems to me like impossible.
What you want seems more applicable to a Sequence rather than a list. -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

On Mon, May 2, 2011 at 8:16 AM, Ivan Lazar Miljenovic
On 2 May 2011 11:10, John Sneer
wrote: Hello all,
I have rather strange question. I wonder whether there is an obvious solution or not in Haskell. I tried but without defining quite ugly tree-like structures and incorporating IORefs it seems to me like impossible.
What you want seems more applicable to a Sequence rather than a list.
Or a mutable list, something like data MList s a = Nil | Cons (STRef s a) (STRef s (MList s a)) Cheers, -- Felipe.

Well, I have more or less similar solution, but its efficiency for
map/foldr etc. is quite low :-(
Nevertheless, probably no other solution.
BR and thanks
John
--
John Sneer
johnsneer@operamail.com
On Mon, 02 May 2011 08:32 -0300, "Felipe Almeida Lessa"
On Mon, May 2, 2011 at 8:16 AM, Ivan Lazar Miljenovic
wrote: On 2 May 2011 11:10, John Sneer
wrote: Hello all,
I have rather strange question. I wonder whether there is an obvious solution or not in Haskell. I tried but without defining quite ugly tree-like structures and incorporating IORefs it seems to me like impossible.
What you want seems more applicable to a Sequence rather than a list.
Or a mutable list, something like
data MList s a = Nil | Cons (STRef s a) (STRef s (MList s a))
Cheers,
-- Felipe.
-- http://www.fastmail.fm - Email service worth paying for. Try it for free

On 02/05/11 13:10, John Sneer wrote:
Simply: I would like to have direct access into several places in a very long list.
Maybe you could use a zipper. Or just maintain the list split into chunks. So l' = [stuffBefore,hi,stuffAfter]. Or if you want to be able to use each element of hi as a kind of pointer, then l'=[stuffBefore] ++ map (:[]) hi ++ [stuffAfter] Now modification becomes just a matter of replacing the appropriate chunk. Twan
participants (4)
-
Felipe Almeida Lessa
-
Ivan Lazar Miljenovic
-
John Sneer
-
Twan van Laarhoven