
What is the best way to implement data structures that use pointers in Haskell? 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 getObject:: Int -> a f:: Int -> Int 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 f x = case x of 1 -> 2 2 -> 3 .... (etc.) Q: if there are n entries here, how long does looking up (f m) take? Suppose later I update, with something like this: update::Int->Int->(Int->Int)->(Int->Int) update x y f z = (if z==x then y else f x) Q: how is "update x y f" maintained? 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? Thanks, Holden

On Mon, Sep 22, 2014 at 2:26 AM, Holden Lee
What is the best way to implement data structures that use pointers in Haskell?
Think at a higher level. Those structures are used to solve what problem? How could that problem be solved haskell-y? But if you just want some simulation, there's the state monad. You could simulate a malloc-ish memory heap using vanilla Data.Map. -- Kim-Ee
participants (3)
-
Holden Lee
-
Kim-Ee Yeoh
-
Tom Ellis