Skip to content

Commit 0019cce

Browse files
authored
Merge pull request #14 from reflex-frp/patch-map-inner-patch-desugar
Reimplement `MapWithWithMove` in terms of `MapWithPatchingMove`
2 parents 755886b + 290829d commit 0019cce

File tree

6 files changed

+361
-251
lines changed

6 files changed

+361
-251
lines changed

.github/workflows/haskell.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ jobs:
4343
run: cabal build --enable-tests --enable-benchmarks all
4444
- name: Run tests
4545
run: cabal test all
46+
- name: Build Docs
47+
run: cabal haddock

ChangeLog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Revision history for patch
22

3+
## Unreleased
4+
5+
* Rewrite `PatchMapWithMove` in terms of `PatchMapWithPatchingMove`.
6+
Care is taken to make this not a breaking change.
7+
In particular, `PatchMapWithMove` is a newtype of `PatchMapWithPatchingMove`, as is the `NodeInfo` and `From` of `PatchMapWithPatchingMove`'s versions of those.
8+
There are complete constructor and field patterns too, and everything is
9+
exported under the newtype as real constructors and fields would be.
10+
311
## 0.0.4.0
412

513
* Enable PolyKinds

src/Data/Patch/Class.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE ScopedTypeVariables #-}
23
{-# LANGUAGE TypeFamilies #-}
34
-- | The interface for types which represent changes made to other types
45
module Data.Patch.Class where
56

67
import Data.Functor.Identity
8+
import Data.Kind (Type)
79
import Data.Maybe
810
#if !MIN_VERSION_base(4,11,0)
911
import Data.Semigroup (Semigroup(..))
@@ -15,7 +17,7 @@ import Data.Proxy
1517
-- If an instance of 'Patch' is also an instance of 'Semigroup', it should obey
1618
-- the law that @applyAlways (f <> g) == applyAlways f . applyAlways g@.
1719
class Patch p where
18-
type PatchTarget p :: *
20+
type PatchTarget p :: Type
1921
-- | Apply the patch @p a@ to the value @a@. If no change is needed, return
2022
-- 'Nothing'.
2123
apply :: p -> PatchTarget p -> Maybe (PatchTarget p)
@@ -30,7 +32,7 @@ instance Patch (Identity a) where
3032
apply (Identity a) _ = Just a
3133

3234
-- | 'Proxy' can be used as a 'Patch' that does nothing.
33-
instance Patch (Proxy (a :: *)) where
35+
instance forall (a :: Type). Patch (Proxy a) where
3436
type PatchTarget (Proxy a) = a
3537
apply ~Proxy _ = Nothing
3638

src/Data/Patch/DMapWithMove.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ moveDMapKey src dst = case src `geq` dst of
220220
-- @
221221
-- let aMay = DMap.lookup a dmap
222222
-- bMay = DMap.lookup b dmap
223-
-- in maybe id (DMap.insert a) (bMay `mplus` aMay)
224-
-- . maybe id (DMap.insert b) (aMay `mplus` bMay)
223+
-- in maybe id (DMap.insert a) (bMay <> aMay)
224+
-- . maybe id (DMap.insert b) (aMay <> bMay)
225225
-- . DMap.delete a . DMap.delete b $ dmap
226226
-- @
227227
swapDMapKey :: GCompare k => k a -> k a -> PatchDMapWithMove k v

0 commit comments

Comments
 (0)