Created
May 8, 2019 19:52
-
-
Save Beneboe/928520b3c42c27223b9402ca3d8b63c8 to your computer and use it in GitHub Desktop.
F# Tree traversal Test
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
open System | |
// printfn "Hello, world!" | |
type Tree<'a> = | |
| Node of Tree<'a> * Tree<'a> | |
| Leaf of 'a | |
let rec travelTree tree = | |
match tree with | |
| Node (left, right) -> | |
do | |
travelTree left | |
travelTree right | |
| Leaf num -> | |
printfn "Currently at: %i" num |> ignore | |
let getExampleTree = | |
Node | |
( Node | |
( Node (Leaf 1, Leaf 2) | |
, Node | |
( Node (Leaf 3, Leaf 4) | |
, Leaf 5)) | |
, Leaf 6) | |
travelTree getExampleTree |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment