I have looked at many similar questions and searched google for a few hours and I am getting nowhere.
I am trying to access my binary tree module which is in my Tree.fs file from my Program.fs file and in the explorer window I have moved the Tree.fs file above the Program.fs file as suggested in almost all of the other similar questions but this is till not working for me.
My Tree.fs file
namespace Lab2
type Elem = System.IComparable
type Tree = E | T of Tree * Elem * Tree
module BinaryTree =
let emptyTree = E
let rec add = function
| x, E -> T(E, x, E)
| x, T(a, y, b) when x < y -> T(add(x, a), y, b)
| x, T(a, y, b) when y < x -> T(a, y, add(x, b))
| _, s -> s
let rec addList = function
| [], T(a, y, b) -> T(a, y, b)
| x::xs, T(a, y, b) when x < y -> addList(xs, T(add(x, a), y, b))
| x::xs, T(a, y, b) when y < x -> addList(xs, T(a, y, add(x, b)))
| _, s -> s
let rec preorder = function
| T(a, y, b) when a <> E -> y::preorder a
| T(a, y, b) when b <> E -> y::preorder b
| _ -> []
let rec inorder = function
| T(a, y, b) when a <> E -> y::inorder a
| T(a, y, b) when b <> E -> y::inorder b
| _ -> []
let rec postorder = function
| T(a, y, b) when b <> E -> y::preorder b
| T(a, y, b) when a <> E -> y::preorder a
| _ -> []
let rec treeToString = function
| T(a, y, b) when a <> E -> "(node " + y.ToString() + treeToString a
| T(a, y, b) when b <> E -> y.ToString() + treeToString b + ")"
| _ -> "Empty"
My Program.fs file
module Lab2.Program
open Lab2.BinaryTree
let tree = addList([5; 2; 1; 6; 7], emptyTree);;
let inorder_tree = inorder(tree);;
let char_tree = addList(['e';'b';'a';'f';'g'], emptyTree);;
let inorder_char_tree = inorder(char_tree);;
let print = treeToString(char_tree);;
I have tried not using the Lab2 namespace in both of my files and instead just using both files as modules but this still gives me the same error.
I have no blue or red lines in my code, no errors untill I debug
The error only happens on the following line
let tree = addList([5; 2; 1; 6; 7], emptyTree);;
So when debugging it looks like this
Program.fs(66,6): error FS0039: The namespace or module 'Lab2' is not defined
> val inorder_tree : Elem list = []
> val char_tree : Tree = E
> val inorder_char_tree : Elem list = []
> val print : string = "Empty"