-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Combination of #1 and #2 #10
Open
Ericson2314
wants to merge
34
commits into
develop
Choose a base branch
from
dpatch-map-inner-patch
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
d66d5e9
add a couple of types for working with patches
danbornside 732cb14
Update src/Reflex/Patch/Patchable.hs
danbornside b742380
Merge branch 'develop' into patch-dmap-reset
Ericson2314 0918153
Merge remote-tracking branch 'patch/develop' into patch-dmap-reset
Ericson2314 0ec95ff
Add change log entry
Ericson2314 a74f716
Merge remote-tracking branch 'origin/patch-dmap-reset' into dpatch-ma…
Ericson2314 cf7b8fb
Get rid of entirely-_ pattern in Group instances
Ericson2314 7fd18c0
Add notion of heterogenous patch
Ericson2314 aa7311b
WIP: Patch in PatchDMapWithMove's From_Move
Ericson2314 d72221c
Try making the "to" field at a potentially different index
Ericson2314 f78dd16
WIP Generalize DMap patching
Ericson2314 69a7ab8
Over the hill
Ericson2314 3f037af
Get everything type checking again
Ericson2314 6b8b77b
Export Data.Patch.DMapWithMove.By
Ericson2314 ab5bd5d
Remove PatchDMapWithReset now that it has been accounted for
Ericson2314 c99f2d2
Add decidably empty things
Ericson2314 98634c9
Appease hlint
Ericson2314 5a13577
Remove Patchable
Ericson2314 08f13f2
Update ChangeLog.md
Ericson2314 6fcf213
Merge branch 'develop' of github.com:reflex-frp/patch into dpatch-map…
Ericson2314 c3cac44
WIP make old in terms of new
Ericson2314 584334f
Merge branch 'patch-map-inner-patch' into dpatch-map-inner-patch
Ericson2314 6ef716a
Merge branch 'patch-map-inner-patch-desugar' into dpatch-map-inner-patch
Ericson2314 ac8f411
Restore the old `DMapWithMove`,
Ericson2314 48711bc
DMapWithPatchingnMove: Restore old algo
Ericson2314 8e3015a
Simplify type of "To"
Ericson2314 4da27a8
Simplify type of fixup
Ericson2314 76f010e
Delete old code and format a bit
Ericson2314 efb8a9b
Put back Cat.DecidablyEmpty
Ericson2314 62bd0fc
Remove redundant geq
Ericson2314 055f256
Simplify
Ericson2314 76033e9
Improve error
Ericson2314 ccd725a
Merge remote-tracking branch 'origin/develop' into HEAD
Ericson2314 873bad6
Replace Proxy3 with something more appropriate
Ericson2314 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{-# LANGUAGE TypeOperators #-} | ||
-- TODO upstream somwhere else? | ||
module Control.Category.DecidablyEmpty where | ||
|
||
import Control.Category | ||
import Data.Type.Equality | ||
|
||
class Category c => DecidablyEmpty c where | ||
isId :: c a b -> Maybe (a :~: b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
{-# LANGUAGE CPP #-} | ||
{-# LANGUAGE DefaultSignatures #-} | ||
{-# LANGUAGE DerivingStrategies #-} | ||
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE MultiParamTypeClasses #-} | ||
{-# LANGUAGE PolyKinds #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
{-# LANGUAGE TypeOperators #-} | ||
{-# LANGUAGE StandaloneDeriving #-} | ||
|
||
{-| | ||
Description: The module provides the 'Patch' class. | ||
|
@@ -9,20 +18,49 @@ This is a class for types which represent changes made to other types | |
-} | ||
module Data.Patch.Class where | ||
|
||
import qualified Data.Semigroupoid as Cat | ||
import qualified Control.Category as Cat | ||
import Data.Functor.Identity | ||
import Data.Functor.Misc | ||
import Data.Kind (Type) | ||
import Data.Maybe | ||
#if !MIN_VERSION_base(4,11,0) | ||
import Data.Semigroup (Semigroup(..)) | ||
#endif | ||
import Data.Proxy | ||
import Data.Typeable | ||
|
||
class PatchHet p where | ||
type PatchSource p :: Type | ||
type PatchTarget p :: Type | ||
-- | Apply the patch @p a@ to the value @a@. If no change is needed, return | ||
-- 'Nothing'. | ||
applyHet | ||
:: p | ||
-> PatchSource p | ||
-> Either (PatchSource p :~: PatchTarget p) (PatchTarget p) | ||
default applyHet | ||
:: Patch p | ||
=> p | ||
-> PatchSource p | ||
-> Either (PatchSource p :~: PatchTarget p) (PatchTarget p) | ||
applyHet p a = case apply p a of | ||
Nothing -> Left Refl | ||
Just a' -> Right a' | ||
|
||
-- | Apply a 'PatchHet'; if it does nothing, return the original value | ||
applyAlwaysHet :: PatchHet p => p -> PatchSource p -> PatchTarget p | ||
applyAlwaysHet p t = case applyHet p t of | ||
Left Refl -> t | ||
Right t' -> t' | ||
|
||
-- | A 'Patch' type represents a kind of change made to a datastructure. | ||
-- | ||
-- If an instance of 'Patch' is also an instance of 'Semigroup', it should obey | ||
-- the law that @applyAlways (f <> g) == applyAlways f . applyAlways g@. | ||
class Patch p where | ||
type PatchTarget p :: Type | ||
class ( PatchHet p | ||
, PatchSource p ~ PatchTarget p | ||
) => Patch p where | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i like the way you tied these two together, it should make life easier in a lot of cases. |
||
-- | Apply the patch @p a@ to the value @a@. If no change is needed, return | ||
-- 'Nothing'. | ||
apply :: p -> PatchTarget p -> Maybe (PatchTarget p) | ||
|
@@ -32,19 +70,123 @@ applyAlways :: Patch p => p -> PatchTarget p -> PatchTarget p | |
applyAlways p t = fromMaybe t $ apply p t | ||
|
||
-- | 'Identity' can be used as a 'Patch' that always fully replaces the value | ||
instance Patch (Identity a) where | ||
instance PatchHet (Identity a) where | ||
type PatchSource (Identity a) = a | ||
type PatchTarget (Identity a) = a | ||
instance Patch (Identity a) where | ||
apply (Identity a) _ = Just a | ||
|
||
-- | 'Proxy' can be used as a 'Patch' that does nothing. | ||
instance forall (a :: Type). Patch (Proxy a) where | ||
instance forall (a :: Type). PatchHet (Proxy a) where | ||
type PatchSource (Proxy a) = a | ||
type PatchTarget (Proxy a) = a | ||
instance forall (a :: Type). Patch (Proxy a) where | ||
apply ~Proxy _ = Nothing | ||
|
||
-- | Like '(.)', but composes functions that return patches rather than | ||
-- functions that return new values. The Semigroup instance for patches must | ||
-- apply patches right-to-left, like '(.)'. | ||
composePatchFunctions :: (Patch p, Semigroup p) => (PatchTarget p -> p) -> (PatchTarget p -> p) -> PatchTarget p -> p | ||
composePatchFunctions | ||
:: (Patch p, Semigroup p) | ||
=> (PatchTarget p -> p) | ||
-> (PatchTarget p -> p) | ||
-> PatchTarget p -> p | ||
composePatchFunctions g f a = | ||
let fp = f a | ||
in g (applyAlways fp a) <> fp | ||
|
||
|
||
class PatchHet2Base (p :: k -> k -> Type) where | ||
type PatchSource1 p :: k -> Type | ||
type PatchTarget1 p :: k -> Type | ||
|
||
class ( PatchHet2Base p | ||
, PatchHet (p from to) | ||
, PatchSource1 p from ~ PatchSource (p from to) | ||
, PatchTarget1 p to ~ PatchTarget (p from to) | ||
) => PatchHet2Locally (p :: k -> k -> Type) from to where | ||
instance ( PatchHet2Base p | ||
, PatchHet (p from to) | ||
, PatchSource1 p from ~ PatchSource (p from to) | ||
, PatchTarget1 p to ~ PatchTarget (p from to) | ||
) => PatchHet2Locally (p :: k -> k -> Type) from to where | ||
|
||
applyHet2Locally | ||
:: PatchHet2Locally p from to | ||
=> p from to | ||
-> PatchSource1 p from | ||
-> Either (PatchSource1 p from :~: PatchTarget1 p to) (PatchTarget1 p to) | ||
applyHet2Locally = applyHet | ||
|
||
applyAlwaysHet2Locally | ||
:: PatchHet2Locally p from to | ||
=> p from to | ||
-> PatchSource1 p from | ||
-> PatchTarget1 p to | ||
applyAlwaysHet2Locally = applyAlwaysHet | ||
|
||
-- TODO once we can use quantified constraints, perhaps combine PatchHet2Base and | ||
-- PatchHet2Locally, or at least get rid of this. | ||
class PatchHet2Base p => PatchHet2 (p :: k -> k -> Type) where | ||
applyHet2 | ||
:: p from to | ||
-> PatchSource1 p from | ||
-> Either (PatchSource1 p from :~: PatchTarget1 p to) (PatchTarget1 p to) | ||
|
||
applyAlwaysHet2 | ||
:: PatchHet2 p | ||
=> p from to | ||
-> PatchSource1 p from | ||
-> PatchTarget1 p to | ||
applyAlwaysHet2 p t = case applyHet2 p t of | ||
Left Refl -> t | ||
Right t' -> t' | ||
|
||
-- | Connect the classes without quanitified constraints | ||
newtype ProjectLocal p from to = ProjectLocal { unProjectLocal :: p from to } | ||
deriving newtype Cat.Semigroupoid | ||
|
||
instance PatchHet2 p => PatchHet (ProjectLocal p from to) where | ||
type PatchSource (ProjectLocal p from to) = PatchSource1 p from | ||
type PatchTarget (ProjectLocal p from to) = PatchTarget1 p to | ||
applyHet (ProjectLocal p) = applyHet2 p | ||
|
||
instance PatchHet2 p => PatchHet2Base (ProjectLocal p) where | ||
type PatchSource1 (ProjectLocal p) = PatchSource1 p | ||
type PatchTarget1 (ProjectLocal p) = PatchTarget1 p | ||
|
||
class ( PatchHet2Base p | ||
, PatchSource1 p ~ PatchTarget1 p | ||
) => Patch2 p | ||
instance ( PatchHet2Base p | ||
, PatchSource1 p ~ PatchTarget1 p | ||
) => Patch2 p | ||
|
||
-- | 'First2' can be used as a 'Patch' that always fully replaces the value | ||
instance PatchHet (First2 (t :: k -> Type) (from :: k) (to :: k)) where | ||
type PatchSource (First2 t from to) = t from | ||
type PatchTarget (First2 t from to) = t to | ||
applyHet (First2 val) _ = Right val | ||
|
||
data IndexedEq :: (k -> Type) -> k -> k -> Type where | ||
IndexedRefl :: IndexedEq k x x | ||
deriving (Typeable) | ||
|
||
deriving instance Eq (IndexedEq k x y) | ||
deriving instance Ord (IndexedEq k x y) | ||
deriving instance Show (IndexedEq k x y) | ||
deriving instance Read (IndexedEq k x x) | ||
|
||
instance Cat.Category (IndexedEq x) where | ||
id = IndexedRefl | ||
IndexedRefl . IndexedRefl = IndexedRefl | ||
|
||
-- | 'IndexedEq' can be used as a 'Patch' that always does nothing | ||
instance PatchHet (IndexedEq (t :: k -> Type) (a :: k) (b :: k)) where | ||
type PatchSource (IndexedEq t a b) = t a | ||
type PatchTarget (IndexedEq t a b) = t b | ||
applyHet IndexedRefl _ = Left Refl | ||
|
||
instance PatchHet2Base (IndexedEq (t :: k -> Type) :: k -> k -> Type) where | ||
type PatchSource1 (IndexedEq t) = t | ||
type PatchTarget1 (IndexedEq t) = t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this actually necessary to be in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope