How to write function like this? :
unWrap :: F f a -> Either a (f (F f a))
where F - Church encoded free monad.unWrap returns "a" if value is equals to "Pure a" or returns "f_" if value equals to "(Free f_)".
How to write function like this? :
unWrap :: F f a -> Either a (f (F f a))
where F - Church encoded free monad.unWrap returns "a" if value is equals to "Pure a" or returns "f_" if value equals to "(Free f_)".
You can use fromF to convert to another representation, in this case Free f so you can pattern-match, and toF to convert back from Free f.
unwrap :: Functor f => F f a -> Either a (f (F f a))
unwrap u = case fromF u of
Pure x -> Left x
Free v -> Right (fmap toF v)