[Haskell-cafe] Fwd: Pointers by using functions
Holden Lee
holdenlee at alum.mit.edu
Sun Sep 21 19:26:46 UTC 2014
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140921/abce6c62/attachment.html>
More information about the Haskell-Cafe
mailing list