Skip to content

Commit 873bad6

Browse files
committed
Replace Proxy3 with something more appropriate
1 parent ccd725a commit 873bad6

File tree

3 files changed

+35
-31
lines changed

3 files changed

+35
-31
lines changed

src/Data/Functor/Misc.hs

-13
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ are relevant to the use of 'Functor'-based datastructures like
2121
module Data.Functor.Misc
2222
( -- * Const2
2323
Const2 (..)
24-
, Proxy3 (..)
2524
, First2 (..)
2625
, unConst2
2726
, dmapToMap
@@ -43,7 +42,6 @@ module Data.Functor.Misc
4342
, ComposeMaybe (..)
4443
) where
4544

46-
import qualified Control.Category as Cat
4745
import Data.Dependent.Map (DMap)
4846
import qualified Data.Dependent.Map as DMap
4947
import Data.Dependent.Sum
@@ -96,17 +94,6 @@ instance Ord k => GCompare (Const2 k v) where
9694
EQ -> GEQ
9795
GT -> GGT
9896

99-
data Proxy3 :: x -> y -> z -> Type where
100-
Proxy3 :: Proxy3 vx vy vz
101-
deriving ( Show, Read, Eq, Ord
102-
, Functor, Foldable, Traversable
103-
, Typeable
104-
)
105-
106-
instance Cat.Category (Proxy3 x) where
107-
id = Proxy3
108-
~Proxy3 . ~Proxy3 = Proxy3
109-
11097
newtype First2 (t :: k -> Type) (a :: k) (b :: k) = First2 (t b)
11198
deriving ( Show, Read, Eq, Ord
11299
, Functor, Foldable, Traversable

src/Data/Patch/Class.hs

+25-9
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
{-# LANGUAGE DerivingStrategies #-}
44
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
55
{-# LANGUAGE FlexibleInstances #-}
6+
{-# LANGUAGE GADTs #-}
67
{-# LANGUAGE MultiParamTypeClasses #-}
78
{-# LANGUAGE PolyKinds #-}
89
{-# LANGUAGE ScopedTypeVariables #-}
910
{-# LANGUAGE TypeFamilies #-}
1011
{-# LANGUAGE TypeOperators #-}
12+
{-# LANGUAGE StandaloneDeriving #-}
1113

1214
{-|
1315
Description: The module provides the 'Patch' class.
@@ -17,6 +19,7 @@ This is a class for types which represent changes made to other types
1719
module Data.Patch.Class where
1820

1921
import qualified Data.Semigroupoid as Cat
22+
import qualified Control.Category as Cat
2023
import Data.Functor.Identity
2124
import Data.Functor.Misc
2225
import Data.Kind (Type)
@@ -25,7 +28,7 @@ import Data.Maybe
2528
import Data.Semigroup (Semigroup(..))
2629
#endif
2730
import Data.Proxy
28-
import Data.Type.Equality ((:~:) (..))
31+
import Data.Typeable
2932

3033
class PatchHet p where
3134
type PatchSource p :: Type
@@ -165,12 +168,25 @@ instance PatchHet (First2 (t :: k -> Type) (from :: k) (to :: k)) where
165168
type PatchTarget (First2 t from to) = t to
166169
applyHet (First2 val) _ = Right val
167170

168-
-- | 'Proxy3' can be used as a 'Patch' that always does nothing
169-
instance PatchHet (Proxy3 (t :: k -> Type) (a :: k) (a :: k)) where
170-
type PatchSource (Proxy3 t a a) = t a
171-
type PatchTarget (Proxy3 t a a) = t a
172-
applyHet ~Proxy3 _ = Left Refl
171+
data IndexedEq :: (k -> Type) -> k -> k -> Type where
172+
IndexedRefl :: IndexedEq k x x
173+
deriving (Typeable)
173174

174-
instance PatchHet2Base (Proxy3 (t :: k -> Type) :: k -> k -> Type) where
175-
type PatchSource1 (Proxy3 t) = t
176-
type PatchTarget1 (Proxy3 t) = t
175+
deriving instance Eq (IndexedEq k x y)
176+
deriving instance Ord (IndexedEq k x y)
177+
deriving instance Show (IndexedEq k x y)
178+
deriving instance Read (IndexedEq k x x)
179+
180+
instance Cat.Category (IndexedEq x) where
181+
id = IndexedRefl
182+
IndexedRefl . IndexedRefl = IndexedRefl
183+
184+
-- | 'IndexedEq' can be used as a 'Patch' that always does nothing
185+
instance PatchHet (IndexedEq (t :: k -> Type) (a :: k) (b :: k)) where
186+
type PatchSource (IndexedEq t a b) = t a
187+
type PatchTarget (IndexedEq t a b) = t b
188+
applyHet IndexedRefl _ = Left Refl
189+
190+
instance PatchHet2Base (IndexedEq (t :: k -> Type) :: k -> k -> Type) where
191+
type PatchSource1 (IndexedEq t) = t
192+
type PatchTarget1 (IndexedEq t) = t

src/Data/Patch/DMapWithPatchingMove.hs

+10-9
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import Data.Dependent.Sum (DSum (..))
2828
import qualified Data.Dependent.Map as DMap
2929
import Data.Functor.Constant (Constant (..))
3030
import Data.Functor.Misc
31-
( Const2 (..), Proxy3 (..)
31+
( Const2 (..)
3232
, weakenDMapWith
3333
, dmapToMapWith
3434
)
@@ -53,6 +53,7 @@ import Data.Patch.Class
5353
( Patch (..), PatchHet (..)
5454
, PatchHet2 (..), PatchSource1, PatchTarget1
5555
, applyAlwaysHet2
56+
, IndexedEq (..)
5657
)
5758
import Data.Patch.MapWithPatchingMove (PatchMapWithPatchingMove (..))
5859
import qualified Data.Patch.MapWithPatchingMove as MapWithPatchingMove
@@ -359,10 +360,10 @@ insertDMapKey k v =
359360
-- @
360361
moveDMapKey
361362
:: GCompare k
362-
=> k a -> k a -> PatchDMapWithPatchingMove k (Proxy3 v)
363+
=> k a -> k a -> PatchDMapWithPatchingMove k (IndexedEq v)
363364
moveDMapKey src dst = case src `geq` dst of
364365
Nothing -> PatchDMapWithPatchingMove $ DMap.fromList
365-
[ dst :=> NodeInfo (From_Move (src :=> Flip Proxy3)) To_NonMove
366+
[ dst :=> NodeInfo (From_Move (src :=> Flip IndexedRefl)) To_NonMove
366367
, src :=> NodeInfo From_Delete (To_Move $ Some dst)
367368
]
368369
Just _ -> PatchDMapWithPatchingMove DMap.empty
@@ -377,11 +378,11 @@ moveDMapKey src dst = case src `geq` dst of
377378
-- . maybe id (DMap.insert b) (aMay <> bMay)
378379
-- . DMap.delete a . DMap.delete b $ dmap
379380
-- @
380-
swapDMapKey :: GCompare k => k a -> k a -> PatchDMapWithPatchingMove k (Proxy3 v)
381+
swapDMapKey :: GCompare k => k a -> k a -> PatchDMapWithPatchingMove k (IndexedEq v)
381382
swapDMapKey src dst = case src `geq` dst of
382383
Nothing -> PatchDMapWithPatchingMove $ DMap.fromList
383-
[ dst :=> NodeInfo (From_Move (src :=> Flip Proxy3)) (To_Move $ Some src)
384-
, src :=> NodeInfo (From_Move (dst :=> Flip Proxy3)) (To_Move $ Some dst)
384+
[ dst :=> NodeInfo (From_Move (src :=> Flip IndexedRefl)) (To_Move $ Some src)
385+
, src :=> NodeInfo (From_Move (dst :=> Flip IndexedRefl)) (To_Move $ Some dst)
385386
]
386387
Just _ -> PatchDMapWithPatchingMove DMap.empty
387388

@@ -566,16 +567,16 @@ const2PatchDMapWithPatchingMoveWith
566567
:: forall k v v' a
567568
. (v -> v' a)
568569
-> PatchMapWithPatchingMove k (Proxy v)
569-
-> PatchDMapWithPatchingMove (Const2 k a) (Proxy3 v')
570+
-> PatchDMapWithPatchingMove (Const2 k a) (IndexedEq v')
570571
const2PatchDMapWithPatchingMoveWith f (PatchMapWithPatchingMove p) =
571572
PatchDMapWithPatchingMove $ DMap.fromDistinctAscList $ g <$> Map.toAscList p
572573
where g :: (k, MapWithPatchingMove.NodeInfo k (Proxy v))
573-
-> DSum (Const2 k a) (NodeInfo (Const2 k a) (Proxy3 v'))
574+
-> DSum (Const2 k a) (NodeInfo (Const2 k a) (IndexedEq v'))
574575
g (k, ni) = Const2 k :=> NodeInfo
575576
{ _nodeInfo_from = case MapWithPatchingMove._nodeInfo_from ni of
576577
MapWithPatchingMove.From_Insert v -> From_Insert $ f v
577578
MapWithPatchingMove.From_Delete -> From_Delete
578-
MapWithPatchingMove.From_Move fromKey Proxy -> From_Move $ Const2 fromKey :=> Flip Proxy3
579+
MapWithPatchingMove.From_Move fromKey Proxy -> From_Move $ Const2 fromKey :=> Flip IndexedRefl
579580
, _nodeInfo_to = case MapWithPatchingMove._nodeInfo_to ni of
580581
Nothing -> To_NonMove
581582
Just toKey -> To_Move $ Some (Const2 toKey)

0 commit comments

Comments
 (0)