Copyright | (c) Edward Kmett 2017 |
---|---|
License | BSD2 |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
In order to work with fragments of syntax trees without having to pay
an inordinate cost moving around errors and terms, we need a notion of
Relative
data types that permit relocation cheaply.
Note: There is structure to these classes: Consider the following problematic derivation that show some instances here are incompatible with others.
Delta
1 = -- by instanceMonoid
Delta
Delta
1<>
mempty
= -- by instanceMonoidalDelta
tDelta
1<>
delta
mempty
= -- by instanceRelativeDelta
tdelta
(rel
(Delta
1)mempty
) = -- by instanceRelativeMonoid
tdelta
mempty
= -- by instanceMonoidalDelta
tmempty
= -- by definitionDelta
0
- class Relative a where
- class GRelative f
- grel :: (Generic a, GRelative (Rep a)) => Delta -> a -> a
- frel :: (Functor f, Relative a) => Delta -> f a -> f a
- birel :: (Bifunctor f, Relative a, Relative b) => Delta -> f a b -> f a b
- class (Relative t, Monoid t) => RelativeMonoid t
- class (Relative t, Ord t) => RelativeOrder t
- class RelativeOrder t => StrictRelativeOrder t
Data types with relative positions
class Relative a where Source #
Applying a relative position change as a left monoid action
Laws:
rel
mempty ≡id
rel
(m<>
n) ≡rel
m .rel
n
Preferably rel
relocates in O(1) or logarithmic time at worst or
the container probably isn't well suited for relative use.
Note: rel d = id is a perfectly legitimate definition by these laws.
Note: if you use some stashed delta to slow the descent into your data structure, then you probably need to have nominal roles for your arguments.
Relative () Source # | |
Relative Void Source # | |
Relative Delta Source # | |
Relative Change Source # | |
Relative Edit Source # | |
Relative Grade Source # | |
Relative Token Source # | |
Relative Dyck Source # | |
Relative Closing Source # | |
Relative Opening Source # | |
Relative MismatchError Source # | |
Relative a => Relative [a] Source # | O(n) |
Relative a => Relative (Maybe a) Source # | |
Relative a => Relative (NonEmpty a) Source # | O(n) |
Relative a => Relative (Identity a) Source # | |
Relative (Absolute a) Source # | |
Relative (List a) Source # | |
Relative (Located a) Source # | |
Relative (Queue a) Source # | |
Relative a => Relative (Cat a) Source # | |
(Relative a, Relative b) => Relative (Either a b) Source # | |
(Relative a, Relative b) => Relative (a, b) Source # | |
Relative (Proxy * a) Source # | |
Relative (Map k a) Source # | |
Relative (f a) => Relative (Rev f a) Source # | |
grel'
GRelative (V1 *) Source # | |
GRelative (U1 *) Source # | |
Relative c => GRelative (K1 * i c) Source # | |
(GRelative f, GRelative g) => GRelative ((:+:) * f g) Source # | |
(GRelative f, GRelative g) => GRelative ((:*:) * f g) Source # | |
GRelative f => GRelative (M1 * i c f) Source # | |
(Functor f, GRelative g) => GRelative ((:.:) * * f g) Source # | |
grel :: (Generic a, GRelative (Rep a)) => Delta -> a -> a Source #
We can derive relativity generically.
birel :: (Bifunctor f, Relative a, Relative b) => Delta -> f a b -> f a b Source #
Every bifunctor can be relative.
Relative monoids
class (Relative t, Monoid t) => RelativeMonoid t Source #
Laws:
is a monoid homomorphism.rel
d
rel
d (m<>
n) = rel d m<>
rel d nrel
dmempty
=mempty
TODO: Add RelativeSemigroup
in ghc 8.4
instance RelativeSemigroup Void instance Relative a => RelativeSemigroup (NonEmpty a)
RelativeMonoid () Source # | |
RelativeMonoid Delta Source # | |
RelativeMonoid Dyck Source # | |
Relative a => RelativeMonoid [a] Source # | |
Monoid a => RelativeMonoid (Absolute a) Source # | |
Relative a => RelativeMonoid (List a) Source # | |
(RelativeMonoid a, RelativeMonoid b) => RelativeMonoid (a, b) Source # | |
(StrictRelativeOrder k, Relative a) => RelativeMonoid (Map k a) Source # | |
RelativeMonoid (f a) => RelativeMonoid (Rev f a) Source # | |
Relative orderings
class (Relative t, Ord t) => RelativeOrder t Source #
RelativeOrder () Source # | |
RelativeOrder Delta Source # | |
RelativeOrder a => RelativeOrder [a] Source # | |
RelativeOrder a => RelativeOrder (NonEmpty a) Source # | |
Ord a => RelativeOrder (Absolute a) Source # | |
RelativeOrder a => RelativeOrder (List a) Source # | |
Ord a => RelativeOrder (Located a) Source # | |
(RelativeOrder a, RelativeOrder b) => RelativeOrder (Either a b) Source # | |
(RelativeOrder a, RelativeOrder b) => RelativeOrder (a, b) Source # | |
(StrictRelativeOrder k, RelativeOrder a) => RelativeOrder (Map k a) Source # | |
class RelativeOrder t => StrictRelativeOrder t Source #
A _strict_ relative order
Laws:
x
implies <
yrel
d x <
rel
d y
This can be useful for keys in relative maps because shifting the map can't cause keys to collapse
StrictRelativeOrder () Source # | |
StrictRelativeOrder Delta Source # | |
StrictRelativeOrder a => StrictRelativeOrder [a] Source # | |
StrictRelativeOrder a => StrictRelativeOrder (NonEmpty a) Source # | |
Ord a => StrictRelativeOrder (Absolute a) Source # | |
StrictRelativeOrder a => StrictRelativeOrder (List a) Source # | |
Ord a => StrictRelativeOrder (Located a) Source # | |
(StrictRelativeOrder a, StrictRelativeOrder b) => StrictRelativeOrder (Either a b) Source # | |
(StrictRelativeOrder a, StrictRelativeOrder b) => StrictRelativeOrder (a, b) Source # | |
(StrictRelativeOrder k, StrictRelativeOrder a) => StrictRelativeOrder (Map k a) Source # | |