However, I had this problem
Couldn't match expected type `Int' with actual type `a'
`a' is a rigid type variable bound by
the type signature for lElems :: Ord a => a -> Bst a -> Int
at C:\Users\User\workspace\s\src\Main.hs:3:11
在这里,您可以看到类型和程序的定义。如果它在树中,我想返回元素,如果不是,则返回-1。
next() without parameter invokes the next route handler in framework.
有人可以解释我这里有什么问题吗?
答案 0 :(得分:6)
在n == m
案例中,lElems
返回n
。从类型签名中,该函数被声明为始终返回Int
。这意味着n
必须为Int
,因此无法任何 Ord a
。
尝试在返回之前将可能需要您进一步约束n
转换为Int
; a
。
如果您未找到要查找的内容,请考虑将返回类型更改为-1
,或者更改Maybe a
,而不是返回Either
。 }值。