Hello-

I'm relatively new to Haskell, but have spent a fair amount of time programming
in SML and Scheme.  Up to this point, I've been thrilled by the extras Haskell
offers and fun one can have with lazy evaluation, but now I'm stuck.

How would a seasoned Haskell programmer create and EFFICIENTLY incrementally
modify large highly interlinked data-structures such as you find commonly in 
most graphics programs.  

For instance, consider a doubly-linked ring buffer.  Something like this
might work to create one:

data DbLink = DbLink { left, right :: DbLink, contents :: Int }

let a = DbLink { left = d, right = b, contents = 1 }
    b = DbLink { left = a, right = c, contents = 2 }
    c = DbLink { left = b, right = d, contents = 3 }
    d = DbLink { left = c, right = a, contents = 4 }
in
   a

Easy enough.  The recursive definitions make it easy to hook everything up
but how do you modify it without completely reconstructing it?  If I want to
add a new node between a and b it requires that a's right link and b's left
link must also be updated.  The only way to do that is to make a new a and
b.  This sets off a chain reaction, because now d and c have to be updated
since their links point to the old versions of a and b.

It seems that there is no way to update even the smallest part of the
data-structure without having to traverse the entire thing.  This seems to be
an inherent property of purely functional languages.  This might not be a
big deal with linked lists but consider something much larger and mode complex
like a cyclic graph, etc...

In SML, I'd just cheat and use "ref"'s internally but provide a functional
interface to the user.  I feel as if I'm still not fully converted to the
purely functional mindset and that there must be a way to do this kinds of
thing in the Haskell style.

Am I missing something fundamental here?  I sure hope so...

Jim

-------------------------------------------------------------------------------
 Jim Callahan                                       email: [EMAIL PROTECTED]
 Software Engineer                                         [EMAIL PROTECTED]
 DreamQuest Images                                   
-------------------------------------------------------------------------------



Reply via email to