I recently started learning F# and today I got error that i can't get rid of. I have following code:
open System
[<EntryPoint>]
let main argv =
type BinaryTree =
| Node of int * BinaryTree * BinaryTree
| Empty
let rec printInOrder tree =
match tree with
| Node (data, left, right)
-> printInOrder left
printfn "Node %d" data
printInOrder right
| Empty
-> ()
let binTree =
Node(2,
Node(1, Empty, Empty),
Node(4,
Node(3, Empty, Empty),
Node(5, Empty, Empty)
)
)
printInOrder binTree
0
With this code I'm getting following error:
Incomplete structured construct at or before this point in binding
Unfortunately I have no idea how to fix it. This is code example from book Programming F# 3.0.
I would very much appreciate any kind of answer that could help me understand how to avoid these kind of mistakes in future.
You need to define the types and functions in the proper context (outside of the function).
open System
type BinaryTree =
| Node of int * BinaryTree * BinaryTree
| Empty
let rec printInOrder tree =
match tree with
| Node (data, left, right)
-> printInOrder left
printfn "Node %d" data
printInOrder right
| Empty
-> ()
let binTree =
Node(2,
Node(1, Empty, Empty),
Node(4,
Node(3, Empty, Empty),
Node(5, Empty, Empty)
)
)
[<EntryPoint>]
let main argv =
printInOrder binTree
0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With