roc-lang / examples

All kinds of Roc examples

Home Page:https://www.roc-lang.org/examples

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

example suggestion: tree with a variable number of children

Anton-4 opened this issue · comments

Starting point:

NodeID : U64

Node : { value: Str, children :  List NodeID}

tree : Dict NodeID Node
tree = Dict.empty {}
       |> Dict.insert 0 { value: "hey", children: [1]}
       |> Dict.insert 1 { value: "hey!", children: []}

Brendan also suggested a type like this, which could look nicer/simpler:

Node: [Element { branch: List Node, ...}]

We may want to make a simple example and one optimized for performance but we can worry about that later.

Yes, although I'd keep it simpler here and only show how to make a tree datastructure, without any functions.