{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE GADTs #-}
module Data.Profunctor.FoldM where
import Data.Profunctor

-- https://hackage.haskell.org/package/foldl-1.4.10/docs/Control-Foldl.html#t:FoldM
data FoldM m a b = forall x. FoldM (x -> a -> m x) (m x) (x -> m b)

instance Functor m => Profunctor (FoldM m) where
  dimap :: (a -> b) -> (c -> d) -> FoldM m b c -> FoldM m a d
dimap l :: a -> b
l r :: c -> d
r (FoldM step :: x -> b -> m x
step initial :: m x
initial extract :: x -> m c
extract) = (x -> a -> m x) -> m x -> (x -> m d) -> FoldM m a d
forall (m :: * -> *) a b x.
(x -> a -> m x) -> m x -> (x -> m b) -> FoldM m a b
FoldM (\x :: x
x a :: a
a -> x -> b -> m x
step x
x (a -> b
l a
a)) m x
initial ((c -> d) -> m c -> m d
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap c -> d
r (m c -> m d) -> (x -> m c) -> x -> m d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> m c
extract)

-- instance Choice (FoldM m) where
--   right' (FoldM step initial extract) = FoldM (\x a -> )
--   where
--     step' x (Left l) 
--     step' x (Right)