I'm trying to make a Decision Tree for a game and I have:
data DecisionTree a
= Result a
| Decision [DecisionTree a]
deriving (Eq,Show)`
furthermore, I have
instance Functor DecisionTree where
fmap = liftM
now I have to define
instance Monad DecisionTree where
-- return :: a -> DecisionTree a
return = ...
-- (>>=) :: DecisionTree a -> (a -> DecisionTree b) -> DecisionTree b
(>>=) = ...
Now I'm kinda confused how to fill in the definitions.
To define >>=
I tried splitting the definition into two cases:
(>>=) (Result a) f = f a
(>>=) (Decision ys) f = Decision (fmap (>>= f) ys)
As for return
I thought at least something like
return = Result
but this only builds Result a
and no Decision [DecisionTree a]
.
Am I completely off or am I close?