I have an insert function for a Binary Search Tree in Haskel. My insert functions first two lines look like this
insert :: (Ord a) => BST a -> a -> BST a
insert Nil x = Node x Nil Nil
I know the function works, I have tested it on single numbers. But now I am trying to apply the insert to a list. I tried this code
let mBST = foldr insert Nil [1,2,7,9,3,5]
and I get the following error
Occurs check: cannot construct the infinite type: a0 = BST a0
Expected type: BST (BST a0) -> BST a0 -> BST a0
Actual type: BST (BST a0) -> BST a0 -> BST (BST a0)
In the first argument of `foldr', namely `insert'
In the expression: foldr insert Nil [1, 2, 7, 9, ....]
I there is an error in the BST a -> a -> BST a but I am not sure how to fix it.