I currently have a newtype instance which I should translate into a monad. I am having trouble with defining the bind to this particular monad where the newtype is defined as:
newtype Thing xs = Thing {runThing :: [[xs]]} deriving (Show)
I have defined a join that takes the monad one level down.
join' :: Thing(Thing a) -> Thing a
join' xs = (concat (map runThing (concat (Thing xs))))
and planned to apply the function in the bind like so
Thing xs >>= f = Thing(map (map f) $ (runThing (Thing xs)))
which doesn't compile and also tried:
join' xs = head (concat (runThing xs))
Thing a >>= f =join' (fmap f (Thing a))
does but I understand that it only maps to the head of a list and uses the fmap I defined in a functor like so:
instance Functor Thing where
fmap f (Thing [[]]) = Thing [[]]
fmap f (Thing a) = Thing (nestedMap f a)
How would I build a join that allows me to map and create a new Thing?