This commit is contained in:
Hans Hoeglund 2020-04-16 14:16:11 +01:00
parent b4dc23f76e
commit e5a825ee4c

View File

@ -23,24 +23,12 @@ module Iso.Deriving
)
where
-- import Control.Lens (Iso', iso, to, from, view, coerced, enum) -- TODO loose lens dep!
-- import Control.Monad.Free
-- import Data.Monoid hiding (Product)
import Control.Applicative
import Control.Category
import Data.Bifunctor ()
-- import Data.Maybe (catMaybes)
import Data.Profunctor (Profunctor (..))
import Prelude hiding ((.), id)
-- import Control.Arrow (Kleisli(..))
-- import Control.Monad.State
-- import Data.Functor.Compose
-- import Data.Functor.Product
-- import Data.Functor.Const
-- import Data.Functor.Identity
-- import Data.Coerce (coerce)
-- import Control.Monad.Writer hiding (Product)
type Iso s t a b = forall p f. (Profunctor p, Functor f) => p a (f b) -> p s (f t)
@ -122,6 +110,7 @@ instance (forall x. Isomorphic (f x) (g x), Functor f) => Functor (As1 f g) wher
instance (forall x. Isomorphic (f x) (g x), Applicative f) => Applicative (As1 f g) where
pure :: forall a . a -> As1 f g a
pure x = As1 $ inj @(f _) @(g _) $ pure x
(<*>) :: forall a b. As1 f g (a -> b) -> As1 f g a -> As1 f g b
@ -139,6 +128,7 @@ instance (forall x. Isomorphic (f x) (g x), Alternative f) => Alternative (As1 f
As1 h <|> As1 x = As1 $ inj @(f a) @(g a) $ (prj @(f a) @(g a) h) <|> (prj @(f a) @(g a) x)
instance (forall x. Isomorphic (f x) (g x), Monad f) => Monad (As1 f g) where
(>>=) :: forall a b. As1 f g a -> (a -> As1 f g b) -> As1 f g b
As1 k >>= f = As1 $ inj @(f b) @(g b) $ (prj @(f a) @(g a) k) >>= prj . getAs1 . f