Skip to content

Commit

Permalink
add Typeable n constraint on Action instance for Style
Browse files Browse the repository at this point in the history
Required by an upcoming change to the `Action` class in `monoid-extras`.
  • Loading branch information
byorgey committed Nov 4, 2023
1 parent 75c7212 commit b9ea4ae
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/Diagrams/Core/Style.hs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ instance (Additive v, Traversable v, Floating n) => Transformable (Style v n) wh
transform t = over each (transform t)

-- | Styles have no action on other monoids.
instance A.Action (Style v n) m
instance Typeable n => A.Action (Style v n) m

-- | Show the attributes in the style.
instance Show (Style v n) where
Expand Down
2 changes: 1 addition & 1 deletion src/Diagrams/Core/Transform.hs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ instance (Additive v, Num n) => Monoid (Transformation v n) where
mappend = (<>)

-- | Transformations can act on transformable things.
instance (Transformable a, V a ~ v, N a ~ n) => Action (Transformation v n) a where
instance (Transformable a, Additive v, Num n, V a ~ v, N a ~ n) => Action (Transformation v n) a where
act = transform

-- | Apply a transformation to a vector. Note that any translational
Expand Down
60 changes: 30 additions & 30 deletions src/Diagrams/Core/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -258,24 +258,24 @@ data Annotation

-- | Apply a static annotation at the root of a diagram.
applyAnnotation
:: (Metric v, OrderedField n, Semigroup m)
:: (Metric v, OrderedField n, Typeable n, Semigroup m)
=> Annotation -> QDiagram b v n m -> QDiagram b v n m
applyAnnotation an (QD dt) = QD (D.annot an dt)

-- | Make a diagram into a hyperlink. Note that only some backends
-- will honor hyperlink annotations.
href :: (Metric v, OrderedField n, Semigroup m)
href :: (Metric v, OrderedField n, Typeable n, Semigroup m)
=> String -> QDiagram b v n m -> QDiagram b v n m
href = applyAnnotation . Href

-- | Change the transparency of a 'Diagram' as a group.
opacityGroup, groupOpacity :: (Metric v, OrderedField n, Semigroup m)
opacityGroup, groupOpacity :: (Metric v, OrderedField n, Typeable n, Semigroup m)
=> Double -> QDiagram b v n m -> QDiagram b v n m
opacityGroup = applyAnnotation . OpacityGroup
groupOpacity = applyAnnotation . OpacityGroup

-- | Apply a general Key-Value annotation
keyVal :: (Metric v, OrderedField n, Semigroup m)
keyVal :: (Metric v, OrderedField n, Typeable n, Semigroup m)
=> (String, String) -> QDiagram b v n m -> QDiagram b v n m
keyVal = applyAnnotation . KeyVal

Expand Down Expand Up @@ -351,12 +351,12 @@ getU' :: (Monoid u', u :>: u') => D.DUALTree d u a l -> u'
getU' = maybe mempty (maybe mempty id . get) . D.getU

-- | Lens onto the 'Envelope' of a 'QDiagram'.
envelope :: (OrderedField n, Metric v, Monoid' m)
envelope :: (OrderedField n, Typeable n, Metric v, Monoid' m)
=> Lens' (QDiagram b v n m) (Envelope v n)
envelope = lens (unDelete . getU' . view _Wrapped') (flip setEnvelope)

-- | Replace the envelope of a diagram.
setEnvelope :: forall b v n m. ( OrderedField n, Metric v
setEnvelope :: forall b v n m. ( OrderedField n, Typeable n, Metric v
, Monoid' m)
=> Envelope v n -> QDiagram b v n m -> QDiagram b v n m
setEnvelope e =
Expand All @@ -366,12 +366,12 @@ setEnvelope e =
)

-- | Lens onto the 'Trace' of a 'QDiagram'.
trace :: (Metric v, OrderedField n, Semigroup m) =>
trace :: (Metric v, OrderedField n, Typeable n, Semigroup m) =>
Lens' (QDiagram b v n m) (Trace v n)
trace = lens (unDelete . getU' . view _Wrapped') (flip setTrace)

-- | Replace the trace of a diagram.
setTrace :: forall b v n m. ( OrderedField n, Metric v
setTrace :: forall b v n m. ( OrderedField n, Typeable n, Metric v
, Semigroup m)
=> Trace v n -> QDiagram b v n m -> QDiagram b v n m
setTrace t = over _Wrapped' ( D.applyUpre (inj . toDeletable $ t)
Expand All @@ -381,16 +381,16 @@ setTrace t = over _Wrapped' ( D.applyUpre (inj . toDeletable $ t)

-- | Lens onto the 'SubMap' of a 'QDiagram' (/i.e./ an association from
-- names to subdiagrams).
subMap :: (Metric v, Semigroup m, OrderedField n)
subMap :: (Metric v, Semigroup m, OrderedField n, Typeable n)
=> Lens' (QDiagram b v n m) (SubMap b v n m)
subMap = lens (unDelete . getU' . view _Wrapped') (flip setMap)
where
setMap :: (Metric v, Semigroup m, OrderedField n) =>
setMap :: (Metric v, Semigroup m, OrderedField n, Typeable n) =>
SubMap b v n m -> QDiagram b v n m -> QDiagram b v n m
setMap m = over _Wrapped' ( D.applyUpre . inj . toDeletable $ m)

-- | Get a list of names of subdiagrams and their locations.
names :: (Metric v, Semigroup m, OrderedField n)
names :: (Metric v, Semigroup m, OrderedField n, Typeable n)
=> QDiagram b v n m -> [(Name, [Point v n])]
names = (map . second . map) location . M.assocs . view (subMap . _Wrapped')

Expand All @@ -399,14 +399,14 @@ names = (map . second . map) location . M.assocs . view (subMap . _Wrapped')
-- included/. The upshot of this knot-tying is that if @d' = d #
-- named x@, then @lookupName x d' == Just d'@ (instead of @Just
-- d@).
nameSub :: (IsName nm , Metric v, OrderedField n, Semigroup m)
nameSub :: (IsName nm , Metric v, OrderedField n, Typeable n, Semigroup m)
=> (QDiagram b v n m -> Subdiagram b v n m) -> nm -> QDiagram b v n m -> QDiagram b v n m
nameSub s n d = d'
where d' = over _Wrapped' (D.applyUpre . inj . toDeletable $ fromNames [(n,s d')]) d

-- | Lookup the most recent diagram associated with (some
-- qualification of) the given name.
lookupName :: (IsName nm, Metric v, Semigroup m, OrderedField n)
lookupName :: (IsName nm, Metric v, Semigroup m, OrderedField n, Typeable n)
=> nm -> QDiagram b v n m -> Maybe (Subdiagram b v n m)
lookupName n d = lookupSub (toName n) (d^.subMap) >>= listToMaybe

Expand All @@ -415,7 +415,7 @@ lookupName n d = lookupSub (toName n) (d^.subMap) >>= listToMaybe
-- subdiagram associated with (some qualification of) the name,
-- or perform the identity transformation if the name does not exist.
withName :: (IsName nm, Metric v
, Semigroup m, OrderedField n)
, Semigroup m, OrderedField n, Typeable n)
=> nm -> (Subdiagram b v n m -> QDiagram b v n m -> QDiagram b v n m)
-> QDiagram b v n m -> QDiagram b v n m
withName n f d = maybe id f (lookupName n d) d
Expand All @@ -425,7 +425,7 @@ withName n f d = maybe id f (lookupName n d) d
-- collection of all such subdiagrams associated with (some
-- qualification of) the given name.
withNameAll :: (IsName nm, Metric v
, Semigroup m, OrderedField n)
, Semigroup m, OrderedField n, Typeable n)
=> nm -> ([Subdiagram b v n m] -> QDiagram b v n m -> QDiagram b v n m)
-> QDiagram b v n m -> QDiagram b v n m
withNameAll n f d = f (fromMaybe [] (lookupSub (toName n) (d^.subMap))) d
Expand All @@ -436,7 +436,7 @@ withNameAll n f d = f (fromMaybe [] (lookupSub (toName n) (d^.subMap))) d
-- of) each name. Do nothing (the identity transformation) if any
-- of the names do not exist.
withNames :: (IsName nm, Metric v
, Semigroup m, OrderedField n)
, Semigroup m, OrderedField n, Typeable n)
=> [nm] -> ([Subdiagram b v n m] -> QDiagram b v n m -> QDiagram b v n m)
-> QDiagram b v n m -> QDiagram b v n m
withNames ns f d = maybe id f ns' d
Expand All @@ -446,7 +446,7 @@ withNames ns f d = maybe id f ns' d

-- | \"Localize\" a diagram by hiding all the names, so they are no
-- longer visible to the outside.
localize :: forall b v n m. (Metric v, OrderedField n, Semigroup m)
localize :: forall b v n m. (Metric v, OrderedField n, Typeable n, Semigroup m)
=> QDiagram b v n m -> QDiagram b v n m
localize = over _Wrapped' ( D.applyUpre (inj (deleteL :: Deletable (SubMap b v n m)))
. D.applyUpost (inj (deleteR :: Deletable (SubMap b v n m)))
Expand Down Expand Up @@ -487,12 +487,12 @@ mkQD' l e t n q
-- probably only makes sense in vector spaces of dimension lower
-- than 3, but in theory it could make sense for, say, 3-dimensional
-- diagrams when viewed by 4-dimensional beings.
instance (Metric v, OrderedField n, Semigroup m)
instance (Metric v, OrderedField n, Typeable n, Semigroup m)
=> Monoid (QDiagram b v n m) where
mempty = QD D.empty
mappend = (<>)

instance (Metric v, OrderedField n, Semigroup m)
instance (Metric v, OrderedField n, Typeable n, Semigroup m)
=> Semigroup (QDiagram b v n m) where
(QD d1) <> (QD d2) = QD (d2 <> d1)
-- swap order so that primitives of d2 come first, i.e. will be
Expand All @@ -501,7 +501,7 @@ instance (Metric v, OrderedField n, Semigroup m)
-- | A convenient synonym for 'mappend' on diagrams, designed to be
-- used infix (to help remember which diagram goes on top of which
-- when combining them, namely, the first on top of the second).
atop :: (OrderedField n, Metric v, Semigroup m)
atop :: (OrderedField n, Typeable n, Metric v, Semigroup m)
=> QDiagram b v n m -> QDiagram b v n m -> QDiagram b v n m
atop = (<>)

Expand Down Expand Up @@ -537,50 +537,50 @@ instance Functor (QDiagram b v n) where

---- HasStyle

instance (Metric v, OrderedField n, Semigroup m)
instance (Metric v, OrderedField n, Typeable n, Semigroup m)
=> HasStyle (QDiagram b v n m) where
applyStyle = over _Wrapped' . D.applyD . inj
. (inR :: Style v n -> Transformation v n :+: Style v n)

---- Juxtaposable

instance (Metric v, OrderedField n, Monoid' m)
instance (Metric v, OrderedField n, Typeable n, Monoid' m)
=> Juxtaposable (QDiagram b v n m) where
juxtapose = juxtaposeDefault

---- Enveloped

instance (Metric v, OrderedField n, Monoid' m)
instance (Metric v, OrderedField n, Typeable n, Monoid' m)
=> Enveloped (QDiagram b v n m) where
getEnvelope = view envelope

---- Traced

instance (Metric v, OrderedField n, Semigroup m)
instance (Metric v, OrderedField n, Typeable n, Semigroup m)
=> Traced (QDiagram b v n m) where
getTrace = view trace

---- HasOrigin

-- | Every diagram has an intrinsic \"local origin\" which is the
-- basis for all combining operations.
instance (Metric v, OrderedField n, Semigroup m)
instance (Metric v, OrderedField n, Typeable n, Semigroup m)
=> HasOrigin (QDiagram b v n m) where
moveOriginTo = translate . (origin .-.)

---- Transformable

-- | Diagrams can be transformed by transforming each of their
-- components appropriately.
instance (OrderedField n, Metric v, Semigroup m)
instance (OrderedField n, Typeable n, Metric v, Semigroup m)
=> Transformable (QDiagram b v n m) where
transform = over _Wrapped' . D.applyD . transfToAnnot

---- Qualifiable

-- | Diagrams can be qualified so that all their named points can
-- now be referred to using the qualification prefix.
instance (Metric v, OrderedField n, Semigroup m)
instance (Metric v, OrderedField n, Typeable n, Semigroup m)
=> Qualifiable (QDiagram b v n m) where
(.>>) = over _Wrapped' . D.applyD . inj . toName

Expand Down Expand Up @@ -618,11 +618,11 @@ subPoint p = Subdiagram
instance Functor (Subdiagram b v n) where
fmap f (Subdiagram d a) = Subdiagram (fmap f d) a

instance (OrderedField n, Metric v, Monoid' m)
instance (OrderedField n, Typeable n, Metric v, Monoid' m)
=> Enveloped (Subdiagram b v n m) where
getEnvelope (Subdiagram d a) = transform (transfFromAnnot a) $ getEnvelope d

instance (OrderedField n, Metric v, Semigroup m)
instance (OrderedField n, Typeable n, Metric v, Semigroup m)
=> Traced (Subdiagram b v n m) where
getTrace (Subdiagram d a) = transform (transfFromAnnot a) $ getTrace d

Expand All @@ -646,7 +646,7 @@ location (Subdiagram _ a) = transform (transfFromAnnot a) origin
-- attributes. @getSub@ simply applies the transformation and
-- attributes to the diagram to get the corresponding \"top-level\"
-- diagram.
getSub :: (Metric v, OrderedField n, Semigroup m)
getSub :: (Metric v, OrderedField n, Typeable n, Semigroup m)
=> Subdiagram b v n m -> QDiagram b v n m
getSub (Subdiagram d a) = over _Wrapped' (D.applyD a) d

Expand Down

0 comments on commit b9ea4ae

Please sign in to comment.