Sat Jun 2 12:14:57 EDT 2018
I don't understand what retract does:
retract :: Monad f => Free f a -> f a
How can it convert a tree into a node?
*Main> retract $ Free [Pure 1, Free [Pure 2]]
So it uses the concatenation operation of  here.
Which means it uses at least applicative.
Ok, obvious: it uses the Monad constraint on f to perform the functor
So if I want to flatten an s-expression into a path relation, I just
need to define a monad for it and then use retract?
How to create a monad for
Node t [t]
What about this. Use hoistFree to map the tree onto some monad, then
use the monad to retract?
No this is all getting too complicated.
I have a tree.
This is a monadic value (of leaf nodes).
I can tack stuff onto the free monad which provides context.
Now, how to iterate?
Basically, how to unpack one level of the monad?
Bind already does the recursive map.
It seems that these two monads need to be kept separate, such that
once can be used to wrap values inside the functor.
How is bind defined for free? That is the key really.
instance (Functor f) => Monad (Free f) where
return = Pure
(Pure x) >>= f = f x
(Free xs) >>= f = Free $ fmap (>>= f) xs
Basically, I want a different bind.
One where fmap introduces context
Maybe iter is the way to go anway.
EDIT: So for EDIF, I'm just making an explicit iteration. The data
structure is not specific enough to do this with iterM without some
serious workarounds inside the iterated function.