Created
November 3, 2016 20:12
-
-
Save BrianHicks/988e31bd221d2164f984227ecbe1fa1e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Tree exposing (..) | |
import Html exposing (text) | |
import Json.Decode exposing (..) | |
import Json.Decode.Extra exposing (lazy) | |
type BST | |
= Branch BST Int BST | |
| Leaf | |
bst : Decoder BST | |
bst = | |
oneOf | |
[ null Leaf | |
, object3 | |
Branch | |
("left" := (lazy (\_ -> bst))) | |
("value" := int) | |
("right" := (lazy (\_ -> bst))) | |
] | |
data = | |
"""{ | |
"value": 2, | |
"left": { | |
"value": 1, | |
"left": null, | |
"right": null | |
}, | |
"right": { | |
"value": 3, | |
"left": null, | |
"right": null | |
} | |
}""" | |
goal : BST | |
goal = | |
Branch | |
(Branch Leaf 1 Leaf) | |
2 | |
(Branch Leaf 3 Leaf) | |
main = | |
data | |
|> decodeString bst | |
|> toString | |
|> text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment