Make a function that counts the next element in the binary tree.
data BSearchTree a = Nil | Node a (BSearchTree a) (BSearchTree a)
deriving (Show, Eq)
successor :: (Ord a) => a -> BSearchTree a -> Maybe a
successor a = if a Nil then Just succ Nil
else if a (Node _ t1 t2)
then Just succ a (Node _ t1 t2)
else Nothing
Found hole: _ :: a5 Where: ‘a5’ is an ambiguous type variable • In the first argument of ‘Node’, namely ‘_’ In the first argument of ‘a’, namely ‘(Node _ t1 t2)’ In the expression: a (Node _ t1 t2) • Relevant bindings include a :: a (bound at desktop/Aufgabe6.4.hs:32:11) successor :: a -> BSearchTree a -> Maybe a (bound at desktop/Aufgabe6.4.hs:32:1) Constraints include Ord a (from desktop/Aufgabe6.4.hs:30:1-53) | | else if a (Node _ t1 t2)
don't really understand, what the error means...
In your code, there are two underscores (_) at the right side of the successor function, these are typed holes [haskell-wiki].
Typed holes are useful to let the compiler generate the type of the item that should be placed there, if it is hard to figure this out yourself. On QA sites, like StackOverflow, typed holes are frequently used to provide a solution where the OP still needs to implement certain aspects.
In this specific case, you will thus need to fill in some expression for the _ in the two subexpressions (Node _ t1 t2) (not per se the same expression in the two cases).
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