【发布时间】:2015-02-13 04:57:18
【问题描述】:
我在 Haskel 中有一个二叉搜索树的插入函数。我的插入函数前两行如下所示
insert :: (Ord a) => BST a -> a -> BST a
insert Nil x = Node x Nil Nil
我知道该功能有效,我已经在单个数字上对其进行了测试。但现在我正在尝试将插入应用到列表中。我试过这段代码
let mBST = foldr insert Nil [1,2,7,9,3,5]
我收到以下错误
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, ....]
我在 BST a -> a -> BST a 中有一个错误,但我不知道如何修复它。
【问题讨论】:
标签: haskell functional-programming binary-search-tree