Я пытаюсь создать мою Btree
монаду, и я не знаю, как определить return
для этого, так как я хочу поместить значение в Node (Leaf value)
и оставить другую ветку пустой.
module Tree where
import Control.Monad
data Btree a=Node (Btree a)(Btree a)|Leaf a
Проблема возникает, если я хочу ввести значение в монаду:
instance Monad Btree where
(>>=) (Leaf x) f = f x
(>>=) (Node a b) f=Node (a>>=f) (b>>=f)
return t=Node (Leaf t) # i want to partially apply `Node` to not have to specify the other branch . Do i need an additional ADT ? `Leaf/Node/Root` ? for single elements ?
P.S При попытке запустить это с return=Leaf
или return t=Node (Leaf t)(Leaf t)
я также получаю ошибку:
* No instance for (Applicative Btree)
arising from the superclasses of an instance declaration
* In the instance declaration for `Monad Btree'