mirror of
https://github.com/github/semantic.git
synced 2024-12-26 00:12:29 +03:00
Define GAlign over Union non-inductively.
This commit is contained in:
parent
ba895fec3f
commit
711dcdb203
@ -4,6 +4,7 @@ module Data.Align.Generic where
|
|||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Data.Align
|
import Data.Align
|
||||||
import Data.Functor.Identity
|
import Data.Functor.Identity
|
||||||
|
import Data.Proxy
|
||||||
import Data.These
|
import Data.These
|
||||||
import Data.Union
|
import Data.Union
|
||||||
import GHC.Generics
|
import GHC.Generics
|
||||||
@ -27,11 +28,8 @@ instance GAlign Maybe where
|
|||||||
instance GAlign Identity where
|
instance GAlign Identity where
|
||||||
galignWith f (Identity a) (Identity b) = Just (Identity (f (These a b)))
|
galignWith f (Identity a) (Identity b) = Just (Identity (f (These a b)))
|
||||||
|
|
||||||
instance (GAlign f, GAlign (Union fs)) => GAlign (Union (f ': fs)) where
|
instance (Apply1 GAlign fs) => GAlign (Union fs) where
|
||||||
galignWith f u1 u2 = case (decompose u1, decompose u2) of
|
galignWith f = (join .) . apply1_2' (Proxy :: Proxy GAlign) (\ inj -> (fmap inj .) . galignWith f)
|
||||||
(Left u1', Left u2') -> weaken <$> galignWith f u1' u2'
|
|
||||||
(Right r1, Right r2) -> inj <$> galignWith f r1 r2
|
|
||||||
_ -> Nothing
|
|
||||||
|
|
||||||
instance GAlign (Union '[]) where
|
instance GAlign (Union '[]) where
|
||||||
galignWith _ _ _ = Nothing
|
galignWith _ _ _ = Nothing
|
||||||
|
Loading…
Reference in New Issue
Block a user