{-# LANGUAGE PackageImports #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE UndecidableInstances #-}
module Data.Generics.Sum.Subtype
(
AsSubtype (..)
) where
import "this" Data.Generics.Internal.Optics
import "generic-lens-core" Data.Generics.Internal.Void
import qualified "generic-lens-core" Data.Generics.Sum.Internal.Subtype as Core
class AsSubtype sub sup where
_Sub :: Prism' sup sub
_Sub = (sub -> sup) -> (sup -> Either sup sub) -> Prism' sup sub
forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism sub -> sup
forall sub sup. AsSubtype sub sup => sub -> sup
injectSub (\sup
i -> Either sup sub
-> (sub -> Either sup sub) -> Maybe sub -> Either sup sub
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (sup -> Either sup sub
forall a b. a -> Either a b
Left sup
i) sub -> Either sup sub
forall a b. b -> Either a b
Right (sup -> Maybe sub
forall sub sup. AsSubtype sub sup => sup -> Maybe sub
projectSub sup
i))
{-# INLINE _Sub #-}
injectSub :: sub -> sup
injectSub
= Prism' sup sub -> sub -> sup
forall k (is :: IxList) t b.
Is k A_Review =>
Optic' k is t b -> b -> t
review (AsSubtype sub sup => Prism' sup sub
forall sub sup. AsSubtype sub sup => Prism' sup sub
_Sub @sub @sup)
projectSub :: sup -> Maybe sub
projectSub
= (sup -> Maybe sub)
-> (sub -> Maybe sub) -> Either sup sub -> Maybe sub
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe sub -> sup -> Maybe sub
forall a b. a -> b -> a
const Maybe sub
forall a. Maybe a
Nothing) sub -> Maybe sub
forall a. a -> Maybe a
Just (Either sup sub -> Maybe sub)
-> (sup -> Either sup sub) -> sup -> Maybe sub
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Prism' sup sub -> sup -> Either sup sub
forall k (is :: IxList) s t a b.
Is k An_AffineTraversal =>
Optic k is s t a b -> s -> Either t a
matching (AsSubtype sub sup => Prism' sup sub
forall sub sup. AsSubtype sub sup => Prism' sup sub
_Sub @sub @sup)
{-# MINIMAL (injectSub, projectSub) | _Sub #-}
instance Core.Context sub sup => AsSubtype sub sup where
_Sub :: Prism' sup sub
_Sub = Prism' sup sub -> Prism' sup sub
forall s t a b. Prism s t a b -> Prism s t a b
normalisePrism ((forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ A_Prism p i (Curry NoIx i) sup sup sub sub)
-> Prism' sup sub
forall k (is :: IxList) s t a b.
(forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ k p i (Curry is i) s t a b)
-> Optic k is s t a b
Optic forall sub sup. Context sub sup => Prism' sup sub
forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ A_Prism p i (Curry NoIx i) sup sup sub sub
Core.derived)
{-# INLINE _Sub #-}
instance {-# OVERLAPPING #-} AsSubtype a a where
_Sub :: Prism' a a
_Sub = (forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ A_Prism p i (Curry NoIx i) a a a a)
-> Prism' a a
forall k (is :: IxList) s t a b.
(forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ k p i (Curry is i) s t a b)
-> Optic k is s t a b
Optic forall a. a -> a
forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ A_Prism p i (Curry NoIx i) a a a a
id
{-# INLINE _Sub #-}
instance {-# OVERLAPPING #-} AsSubtype a Void where
injectSub :: a -> Void
injectSub = a -> Void
forall a. HasCallStack => a
undefined
projectSub :: Void -> Maybe a
projectSub = Void -> Maybe a
forall a. HasCallStack => a
undefined
instance {-# OVERLAPPING #-} AsSubtype Void a where
injectSub :: Void -> a
injectSub = Void -> a
forall a. HasCallStack => a
undefined
projectSub :: a -> Maybe Void
projectSub = a -> Maybe Void
forall a. HasCallStack => a
undefined