<div dir="ltr"><div class="gmail_quote"><div dir="ltr">What is the best way to implement data structures that use pointers in Haskell?<div><br></div><div>My first thought is as follows. Suppose for simplicity the labels are just integers, and each object need to point to one other one. I would have a </div><div><br></div><div>getObject:: Int -> a</div><div>f:: Int -> Int</div><div><br></div><div>But I don't understand how Haskell maintains functions in memory, and in particular whether lookup/update is efficient. So suppose I define a f</div><div><br></div><div>f x = case x of </div><div> 1 -> 2</div><div> 2 -> 3</div><div>.... (etc.)</div><div><br></div><div>Q: if there are n entries here, how long does looking up (f m) take?</div><div><br></div><div>Suppose later I update, with something like this:</div><div><br></div><div>update::Int->Int->(Int->Int)->(Int->Int)</div><div>update x y f z = (if z==x then y else f x)</div><div><br></div><div>Q: how is "update x y f" maintained?</div><div><br></div><div>Is using a f::Int->Int like using a pointer in terms of time complexity, and if not, what data structure should I use instead?</div><div><br></div><div>Thanks,</div><div>Holden</div></div>
</div><br></div>