Skip to content

Instantly share code, notes, and snippets.

@supermacro
Created November 18, 2020 15:04
Show Gist options
  • Save supermacro/742eafee5242d6793b25135625d4bdd6 to your computer and use it in GitHub Desktop.
Save supermacro/742eafee5242d6793b25135625d4bdd6 to your computer and use it in GitHub Desktop.
Thinking about tree structures in Elm
-- A tree contains 2 kinds of nodes
-- at depths 1 through 2 you will have a node with a 'replies' field
-- at depth 3 the node is missing a 'replies' field
type alias TreeNode a =
{ a
| body : String
}
type alias WithReplies a =
{ replies : List a }
type CommentTree
= RootNode
(TreeNode (WithReplies
(TreeNode (WithReplies
(TreeNode {})))
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment