On 3/15/06, Sebastian Sylvan <sebastian.sylvan@gmail.com> wrote:
On 3/15/06, minh thu <noteed@gmail.com> wrote:
hi everybody,
i have to implement some data structure which is usually implemented with pointers in imperative languages (can think of it as a double linked list).
i'd like to know how i have to do that.
is there any standard way of converting pointer-based data structure into an inductively-defined data type (like standard haskell list) ? is-it possible ?
or would it be good to define the data structure in c and write a haskell wrapper around the c code ?
thank you a lot, bye, vo minh thu
You can use references, IO, ST or STM.
You can also use laziness (untested!):
data DLink a = (DLink a) a (DLink a) | Nil
test = d1 where d1 = Nil 5 d2 d2 = d1 6 Nil
Eh? I forgot the constructors in the data type (in all three places!) :-) data DLink a = Node (DLink a) a (DLink a) | Nil test = d1 where d1 = Node Nil 5 d2 d2 = Node d1 6 Nil /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862