Skip to content

Instantly share code, notes, and snippets.

@Beneboe
Created May 8, 2019 19:52
Show Gist options
  • Save Beneboe/928520b3c42c27223b9402ca3d8b63c8 to your computer and use it in GitHub Desktop.
Save Beneboe/928520b3c42c27223b9402ca3d8b63c8 to your computer and use it in GitHub Desktop.
F# Tree traversal Test
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