二分木のモナドに (>>=) を正しく実装する方法を理解するのが難しいです。私は次の二分木を持っています:
data BinTree a = Leaf a | Node a (BinTree a) (BinTree a)
deriving (Eq, Ord, Show, Read)
これが私のモナドの (>>=) 演算子です:
Node x l r >>= f = Node (f x) (l >>= f) (r >>= f)
__________^
このエラーが発生し続けます:
Couldn't match type `b' with `BinTree b'
`b' is a rigid type variable bound by
the type signature for
>>= :: BinTree a -> (a -> BinTree b) -> BinTree b
at test.hs:153:5
In the return type of a call of `f'
In the first argument of `Node', namely `(f x)'
In the expression: Node (f x) (l >>= f) (r >>= f)
では、正しいタイプの適切なリーフを取得する方法がわかりませんか?
どんな助けでも大歓迎です
ありがとう