how to implement doubly linked lists

后端 未结 3 2068
夕颜
夕颜 2020-12-05 02:54

Is it possible to have a doubly linked list in Haskell, and what\'s the ideal solution to implementing them? I\'m implementing a scene graph where every widget has a parent

3条回答
  •  难免孤独
    2020-12-05 03:21

    Since you don't (usually) have OO-style objects in Haskell, it's weird to think of data being self-aware. It's important to note that you don't usually make use of aggregation in Haskell data types, favoring composition instead.

    You might want to look into XMonad to see if their design matches your needs (the code is surprisingly readable).

    You also might want to restructure your design so that you never need to look above you (for example, by passing children "callbacks").

    You may also want to see if you can write a zipper for your whole graph.

提交回复
热议问题