Copyright  (c) 20112013 diagramscore team (see LICENSE) 

License  BSDstyle (see LICENSE) 
Maintainer  diagramsdiscuss@googlegroups.com 
Safe Haskell  None 
Language  Haskell2010 
The core library of primitives forming the basis of an embedded domainspecific language for describing and rendering diagrams.
Diagrams.Core.Types defines types and classes for primitives, diagrams, and backends.
 data Annotation = Href String
 applyAnnotation :: (HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Semigroup m) => Annotation > QDiagram b v m > QDiagram b v m
 href :: (HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Semigroup m) => String > QDiagram b v m > QDiagram b v m
 type UpAnnots b v m = Deletable (Envelope v) ::: (Deletable (Trace v) ::: (Deletable (SubMap b v m) ::: (Query v m ::: ())))
 type DownAnnots v = (Transformation v :+: Style v) ::: (Name ::: ())
 transfToAnnot :: Transformation v > DownAnnots v
 transfFromAnnot :: HasLinearMap v => DownAnnots v > Transformation v
 data QDiaLeaf b v m
 = PrimLeaf (Prim b v)
  DelayedLeaf (DownAnnots v > Scalar v > Scalar v > QDiagram b v m)
 withQDiaLeaf :: (Prim b v > r) > ((DownAnnots v > Scalar v > Scalar v > QDiagram b v m) > r) > QDiaLeaf b v m > r
 newtype QDiagram b v m = QD (DUALTree (DownAnnots v) (UpAnnots b v m) Annotation (QDiaLeaf b v m))
 type Diagram b v = QDiagram b v Any
 mkQD :: Prim b v > Envelope v > Trace v > SubMap b v m > Query v m > QDiagram b v m
 mkQD' :: QDiaLeaf b v m > Envelope v > Trace v > SubMap b v m > Query v m > QDiagram b v m
 pointDiagram :: (Fractional (Scalar v), InnerSpace v) => Point v > QDiagram b v m
 envelope :: forall b v m. (OrderedField (Scalar v), InnerSpace v, HasLinearMap v, Monoid' m) => Lens' (QDiagram b v m) (Envelope v)
 trace :: (InnerSpace v, HasLinearMap v, OrderedField (Scalar v), Semigroup m) => Lens' (QDiagram b v m) (Trace v)
 subMap :: (HasLinearMap v, InnerSpace v, Semigroup m, OrderedField (Scalar v)) => Lens' (QDiagram b v m) (SubMap b v m)
 names :: (HasLinearMap v, InnerSpace v, Semigroup m, OrderedField (Scalar v)) => QDiagram b v m > [(Name, [Point v])]
 query :: Monoid m => QDiagram b v m > Query v m
 sample :: Monoid m => QDiagram b v m > Point v > m
 value :: Monoid m => m > QDiagram b v Any > QDiagram b v m
 resetValue :: (Eq m, Monoid m) => QDiagram b v m > QDiagram b v Any
 clearValue :: QDiagram b v m > QDiagram b v Any
 atop :: (HasLinearMap v, OrderedField (Scalar v), InnerSpace v, Semigroup m) => QDiagram b v m > QDiagram b v m > QDiagram b v m
 nameSub :: (IsName n, HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Semigroup m) => (QDiagram b v m > Subdiagram b v m) > n > QDiagram b v m > QDiagram b v m
 lookupName :: (IsName n, HasLinearMap v, InnerSpace v, Semigroup m, OrderedField (Scalar v)) => n > QDiagram b v m > Maybe (Subdiagram b v m)
 withName :: (IsName n, HasLinearMap v, InnerSpace v, Semigroup m, OrderedField (Scalar v)) => n > (Subdiagram b v m > QDiagram b v m > QDiagram b v m) > QDiagram b v m > QDiagram b v m
 withNameAll :: (IsName n, HasLinearMap v, InnerSpace v, Semigroup m, OrderedField (Scalar v)) => n > ([Subdiagram b v m] > QDiagram b v m > QDiagram b v m) > QDiagram b v m > QDiagram b v m
 withNames :: (IsName n, HasLinearMap v, InnerSpace v, Semigroup m, OrderedField (Scalar v)) => [n] > ([Subdiagram b v m] > QDiagram b v m > QDiagram b v m) > QDiagram b v m > QDiagram b v m
 localize :: forall b v m. (HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Semigroup m) => QDiagram b v m > QDiagram b v m
 setEnvelope :: forall b v m. (OrderedField (Scalar v), InnerSpace v, HasLinearMap v, Monoid' m) => Envelope v > QDiagram b v m > QDiagram b v m
 setTrace :: forall b v m. (OrderedField (Scalar v), InnerSpace v, HasLinearMap v, Semigroup m) => Trace v > QDiagram b v m > QDiagram b v m
 data Measure v
 fromOutput :: Measure v > Scalar v
 atMost :: Measure v > Measure v > Measure v
 atLeast :: Measure v > Measure v > Measure v
 data Subdiagram b v m = Subdiagram (QDiagram b v m) (DownAnnots v)
 mkSubdiagram :: QDiagram b v m > Subdiagram b v m
 getSub :: (HasLinearMap v, InnerSpace v, Floating (Scalar v), Ord (Scalar v), Semigroup m) => Subdiagram b v m > QDiagram b v m
 rawSub :: Subdiagram b v m > QDiagram b v m
 location :: HasLinearMap v => Subdiagram b v m > Point v
 subPoint :: (HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Semigroup m) => Point v > Subdiagram b v m
 newtype SubMap b v m = SubMap (Map Name [Subdiagram b v m])
 fromNames :: IsName a => [(a, Subdiagram b v m)] > SubMap b v m
 rememberAs :: IsName a => a > QDiagram b v m > SubMap b v m > SubMap b v m
 lookupSub :: IsName n => n > SubMap b v m > Maybe [Subdiagram b v m]
 data Prim b v where
 Prim :: (Transformable p, Typeable p, Renderable p b) => p > Prim b (V p)
 class HasLinearMap v => Backend b v where
 data DNode b v a
 = DStyle (Style v)
  DTransform (Transformation v)
  DAnnot a
  DDelay
  DPrim (Prim b v)
  DEmpty
 type DTree b v a = Tree (DNode b v a)
 data RNode b v a
 type RTree b v a = Tree (RNode b v a)
 data NullBackend
 type D v = Diagram NullBackend v
 class Transformable t => Renderable t b where
Diagrams
Annotations
Static annotations
data Annotation Source
Static annotations which can be placed at a particular node of a diagram tree.
applyAnnotation :: (HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Semigroup m) => Annotation > QDiagram b v m > QDiagram b v m Source
Apply a static annotation at the root of a diagram.
href :: (HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Semigroup m) => String > QDiagram b v m > QDiagram b v m Source
Make a diagram into a hyperlink. Note that only some backends will honor hyperlink annotations.
Dynamic (monoidal) annotations
type UpAnnots b v m = Deletable (Envelope v) ::: (Deletable (Trace v) ::: (Deletable (SubMap b v m) ::: (Query v m ::: ()))) Source
Monoidal annotations which travel up the diagram tree, i.e. which are aggregated from component diagrams to the whole:
 envelopes (see Diagrams.Core.Envelope). The envelopes are "deletable" meaning that at any point we can throw away the existing envelope and replace it with a new one; sometimes we want to consider a diagram as having a different envelope unrelated to its "natural" envelope.
 traces (see Diagrams.Core.Trace), also deletable.
 name/subdiagram associations (see Diagrams.Core.Names)
 query functions (see Diagrams.Core.Query)
type DownAnnots v = (Transformation v :+: Style v) ::: (Name ::: ()) Source
Monoidal annotations which travel down the diagram tree, i.e. which accumulate along each path to a leaf (and which can act on the upwardstravelling annotations):
 styles (see Diagrams.Core.Style)
 names (see Diagrams.Core.Names)
transfToAnnot :: Transformation v > DownAnnots v Source
Inject a transformation into a default downwards annotation value.
transfFromAnnot :: HasLinearMap v => DownAnnots v > Transformation v Source
Extract the (total) transformation from a downwards annotation value.
Basic type definitions
A leaf in a QDiagram
tree is either a Prim
, or a "delayed"
QDiagram
which expands to a real QDiagram
once it learns the
"final context" in which it will be rendered. For example, in
order to decide how to draw an arrow, we must know the precise
transformation applied to it (since the arrow head and tail are
scaleinvariant).
PrimLeaf (Prim b v)  
DelayedLeaf (DownAnnots v > Scalar v > Scalar v > QDiagram b v m)  The 
withQDiaLeaf :: (Prim b v > r) > ((DownAnnots v > Scalar v > Scalar v > QDiagram b v m) > r) > QDiaLeaf b v m > r Source
The fundamental diagram type is represented by trees of
primitives with various monoidal annotations. The Q
in
QDiagram
stands for "Queriable", as distinguished from
Diagram
, a synonym for QDiagram
with the query type
specialized to Any
.
QD (DUALTree (DownAnnots v) (UpAnnots b v m) Annotation (QDiaLeaf b v m)) 
Functor (QDiagram b v)  
Typeable (* > * > * > *) QDiagram  
(HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Semigroup m) => Monoid (QDiagram b v m)  Diagrams form a monoid since each of their components do: the empty diagram has no primitives, an empty envelope, an empty trace, no named subdiagrams, and a constantly empty query function. Diagrams compose by aligning their respective local origins. The new diagram has all the primitives and all the names from the two diagrams combined, and query functions are combined pointwise. The first diagram goes on top of the second. "On top of" probably only makes sense in vector spaces of dimension lower than 3, but in theory it could make sense for, say, 3dimensional diagrams when viewed by 4dimensional beings. 
(HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Semigroup m) => Semigroup (QDiagram b v m)  
Wrapped (QDiagram b v m)  
(HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Semigroup m) => HasOrigin (QDiagram b v m)  Every diagram has an intrinsic "local origin" which is the basis for all combining operations. 
(HasLinearMap v, OrderedField (Scalar v), InnerSpace v, Semigroup m) => Transformable (QDiagram b v m)  Diagrams can be transformed by transforming each of their components appropriately. 
(HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Semigroup m) => Qualifiable (QDiagram b v m)  Diagrams can be qualified so that all their named points can now be referred to using the qualification prefix. 
(HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Semigroup m) => HasStyle (QDiagram b v m)  
(HasLinearMap v, VectorSpace v, Ord (Scalar v), InnerSpace v, Semigroup m, Fractional (Scalar v), Floating (Scalar v)) => Traced (QDiagram b v m)  
(HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Monoid' m) => Enveloped (QDiagram b v m)  
(HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Monoid' m) => Juxtaposable (QDiagram b v m)  
Rewrapped (QDiagram b v m) (QDiagram b' v' m')  
type Unwrapped (QDiagram b v m) = DUALTree (DownAnnots v) (UpAnnots b v m) Annotation (QDiaLeaf b v m)  
type V (QDiagram b v m) = v 
Operations on diagrams
Creating diagrams
mkQD :: Prim b v > Envelope v > Trace v > SubMap b v m > Query v m > QDiagram b v m Source
Create a diagram from a single primitive, along with an envelope, trace, subdiagram map, and query function.
mkQD' :: QDiaLeaf b v m > Envelope v > Trace v > SubMap b v m > Query v m > QDiagram b v m Source
Create a diagram from a generic QDiaLeaf, along with an envelope, trace, subdiagram map, and query function.
pointDiagram :: (Fractional (Scalar v), InnerSpace v) => Point v > QDiagram b v m Source
Create a "point diagram", which has no content, no trace, an empty query, and a point envelope.
Extracting information
envelope :: forall b v m. (OrderedField (Scalar v), InnerSpace v, HasLinearMap v, Monoid' m) => Lens' (QDiagram b v m) (Envelope v) Source
Get the envelope of a diagram.
trace :: (InnerSpace v, HasLinearMap v, OrderedField (Scalar v), Semigroup m) => Lens' (QDiagram b v m) (Trace v) Source
Get the trace of a diagram.
subMap :: (HasLinearMap v, InnerSpace v, Semigroup m, OrderedField (Scalar v)) => Lens' (QDiagram b v m) (SubMap b v m) Source
Get the subdiagram map (i.e. an association from names to subdiagrams) of a diagram.
names :: (HasLinearMap v, InnerSpace v, Semigroup m, OrderedField (Scalar v)) => QDiagram b v m > [(Name, [Point v])] Source
Get a list of names of subdiagrams and their locations.
query :: Monoid m => QDiagram b v m > Query v m Source
Get the query function associated with a diagram.
sample :: Monoid m => QDiagram b v m > Point v > m Source
Sample a diagram's query function at a given point.
clearValue :: QDiagram b v m > QDiagram b v Any Source
Set all the query values of a diagram to False
.
Combining diagrams
For many more ways of combining diagrams, see Diagrams.Combinators from the diagramslib package.
atop :: (HasLinearMap v, OrderedField (Scalar v), InnerSpace v, Semigroup m) => QDiagram b v m > QDiagram b v m > QDiagram b v m infixl 6 Source
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).
Modifying diagrams
Names
nameSub :: (IsName n, HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Semigroup m) => (QDiagram b v m > Subdiagram b v m) > n > QDiagram b v m > QDiagram b v m Source
Attach an atomic name to a certain subdiagram, computed from the
given diagram /with the mapping from name to subdiagram
included/. The upshot of this knottying is that if d' = d #
named x
, then lookupName x d' == Just d'
(instead of Just
d
).
lookupName :: (IsName n, HasLinearMap v, InnerSpace v, Semigroup m, OrderedField (Scalar v)) => n > QDiagram b v m > Maybe (Subdiagram b v m) Source
Lookup the most recent diagram associated with (some qualification of) the given name.
withName :: (IsName n, HasLinearMap v, InnerSpace v, Semigroup m, OrderedField (Scalar v)) => n > (Subdiagram b v m > QDiagram b v m > QDiagram b v m) > QDiagram b v m > QDiagram b v m Source
Given a name and a diagram transformation indexed by a subdiagram, perform the transformation using the most recent subdiagram associated with (some qualification of) the name, or perform the identity transformation if the name does not exist.
withNameAll :: (IsName n, HasLinearMap v, InnerSpace v, Semigroup m, OrderedField (Scalar v)) => n > ([Subdiagram b v m] > QDiagram b v m > QDiagram b v m) > QDiagram b v m > QDiagram b v m Source
Given a name and a diagram transformation indexed by a list of subdiagrams, perform the transformation using the collection of all such subdiagrams associated with (some qualification of) the given name.
withNames :: (IsName n, HasLinearMap v, InnerSpace v, Semigroup m, OrderedField (Scalar v)) => [n] > ([Subdiagram b v m] > QDiagram b v m > QDiagram b v m) > QDiagram b v m > QDiagram b v m Source
Given a list of names and a diagram transformation indexed by a list of subdiagrams, perform the transformation using the list of most recent subdiagrams associated with (some qualification of) each name. Do nothing (the identity transformation) if any of the names do not exist.
localize :: forall b v m. (HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Semigroup m) => QDiagram b v m > QDiagram b v m Source
"Localize" a diagram by hiding all the names, so they are no longer visible to the outside.
Other
setEnvelope :: forall b v m. (OrderedField (Scalar v), InnerSpace v, HasLinearMap v, Monoid' m) => Envelope v > QDiagram b v m > QDiagram b v m Source
Replace the envelope of a diagram.
setTrace :: forall b v m. (OrderedField (Scalar v), InnerSpace v, HasLinearMap v, Semigroup m) => Trace v > QDiagram b v m > QDiagram b v m Source
Replace the trace of a diagram.
Measurements
Type of measurement units for attributes.
Output (Scalar v)  
Normalized (Scalar v)  
Local (Scalar v)  
Global (Scalar v)  
MinM (Measure v) (Measure v)  
MaxM (Measure v) (Measure v)  
ZeroM  
NegateM (Measure v)  
PlusM (Measure v) (Measure v)  
ScaleM (Scalar v) (Measure v) 
Eq (Scalar v) => Eq (Measure v)  
(Typeable * v, Data v, Data (Scalar v)) => Data (Measure v)  
Ord (Scalar v) => Ord (Measure v)  
Show (Scalar v) => Show (Measure v)  
VectorSpace (Measure v)  
AdditiveGroup (Measure v)  
(HasLinearMap v, Floating (Scalar v)) => Transformable (Measure v)  
Typeable (* > *) Measure  
type Scalar (Measure v) = Scalar v  
type V (Measure v) = v 
fromOutput :: Measure v > Scalar v Source
atMost :: Measure v > Measure v > Measure v Source
Compute the smaller of two Measure
s. Useful for setting upper
bounds.
atLeast :: Measure v > Measure v > Measure v Source
Compute the larger of two Measure
s. Useful for setting lower
bounds.
Subdiagrams
data Subdiagram b v m Source
A Subdiagram
represents a diagram embedded within the context
of a larger diagram. Essentially, it consists of a diagram
paired with any accumulated information from the larger context
(transformations, attributes, etc.).
Subdiagram (QDiagram b v m) (DownAnnots v) 
Functor (Subdiagram b v)  
(HasLinearMap v, InnerSpace v, OrderedField (Scalar v)) => HasOrigin (Subdiagram b v m)  
(HasLinearMap v, InnerSpace v, Floating (Scalar v)) => Transformable (Subdiagram b v m)  
(OrderedField (Scalar v), HasLinearMap v, InnerSpace v, Semigroup m) => Traced (Subdiagram b v m)  
(OrderedField (Scalar v), InnerSpace v, HasLinearMap v, Monoid' m) => Enveloped (Subdiagram b v m)  
type V (Subdiagram b v m) = v 
mkSubdiagram :: QDiagram b v m > Subdiagram b v m Source
Turn a diagram into a subdiagram with no accumulated context.
getSub :: (HasLinearMap v, InnerSpace v, Floating (Scalar v), Ord (Scalar v), Semigroup m) => Subdiagram b v m > QDiagram b v m Source
Turn a subdiagram into a normal diagram, including the enclosing
context. Concretely, a subdiagram is a pair of (1) a diagram and
(2) a "context" consisting of an extra transformation and
attributes. getSub
simply applies the transformation and
attributes to the diagram to get the corresponding "toplevel"
diagram.
rawSub :: Subdiagram b v m > QDiagram b v m Source
Extract the "raw" content of a subdiagram, by throwing away the context.
location :: HasLinearMap v => Subdiagram b v m > Point v Source
Get the location of a subdiagram; that is, the location of its local origin with respect to the vector space of its parent diagram. In other words, the point where its local origin "ended up".
subPoint :: (HasLinearMap v, InnerSpace v, OrderedField (Scalar v), Semigroup m) => Point v > Subdiagram b v m Source
Create a "point subdiagram", that is, a pointDiagram
(with no
content and a point envelope) treated as a subdiagram with local
origin at the given point. Note this is not the same as
mkSubdiagram . pointDiagram
, which would result in a subdiagram
with local origin at the parent origin, rather than at the given
point.
Subdiagram maps
A SubMap
is a map associating names to subdiagrams. There can
be multiple associations for any given name.
SubMap (Map Name [Subdiagram b v m]) 
Action Name (SubMap b v m)  A name acts on a name map by qualifying every name in it. 
Functor (SubMap b v)  
Monoid (SubMap b v m) 

Semigroup (SubMap b v m)  
Wrapped (SubMap b v m)  
(OrderedField (Scalar v), InnerSpace v, HasLinearMap v) => HasOrigin (SubMap b v m)  
(InnerSpace v, Floating (Scalar v), HasLinearMap v) => Transformable (SubMap b v m)  
Qualifiable (SubMap b v m) 

Rewrapped (SubMap b v m) (SubMap b' v' m')  
type Unwrapped (SubMap b v m) = Map Name [Subdiagram b v m]  
type V (SubMap b v m) = v 
fromNames :: IsName a => [(a, Subdiagram b v m)] > SubMap b v m Source
Construct a SubMap
from a list of associations between names
and subdiagrams.
rememberAs :: IsName a => a > QDiagram b v m > SubMap b v m > SubMap b v m Source
Add a name/diagram association to a submap.
lookupSub :: IsName n => n > SubMap b v m > Maybe [Subdiagram b v m] Source
Look for the given name in a name map, returning a list of subdiagrams associated with that name. If no names match the given name exactly, return all the subdiagrams associated with names of which the given name is a suffix.
Primtives
Ultimately, every diagram is essentially a tree whose leaves are primitives,
basic building blocks which can be rendered by backends. However,
not every backend must be able to render every type of primitive;
the collection of primitives a given backend knows how to render is
determined by instances of Renderable
.
A value of type Prim b v
is an opaque (existentially quantified)
primitive which backend b
knows how to render in vector space v
.
Prim :: (Transformable p, Typeable p, Renderable p b) => p > Prim b (V p) 
HasLinearMap v => Transformable (Prim b v)  The 
HasLinearMap v => Renderable (Prim b v) b  The 
type V (Prim b v) = v 
Backends
class HasLinearMap v => Backend b v where Source
Abstract diagrams are rendered to particular formats by
backends. Each backend/vector space combination must be an
instance of the Backend
class.
A minimal complete definition consists of Render
, Result
,
Options
, and renderRTree
. However, most backends will want to
implement adjustDia
as well; the default definition does
nothing. Some useful standard definitions are provided in the
Diagrams.TwoD.Adjust
module from the diagramslib
package.
An intermediate representation used for rendering primitives.
(Typically, this will be some sort of monad, but it need not
be.) The Renderable
class guarantees that a backend will be
able to convert primitives into this type; how these rendered
primitives are combined into an ultimate Result
is completely
up to the backend.
The result of running/interpreting a rendering operation.
Backendspecific rendering options.
adjustDia :: (Monoid' m, Num (Scalar v)) => b > Options b v > QDiagram b v m > (Options b v, Transformation v, QDiagram b v m) Source
adjustDia
allows the backend to make adjustments to the final
diagram (e.g. to adjust the size based on the options) before
rendering it. It returns a modified options record, the
transformation applied to the diagram (which can be used to
convert attributes whose value is Measure
, or transform
e.g. screen coordinates back into local diagram coordinates),
and the adjusted diagram itself.
See the diagramslib package (particularly the
Diagrams.TwoD.Adjust
module) for some useful implementations.
renderRTree :: b > Options b v > RTree b v Annotation > Result b v Source
Given some options, take a representation of a diagram as a
tree and render it. The RTree
has already been simplified
and has all measurements converted to Output
units.
HasLinearMap v => Backend NullBackend v 
DStyle (Style v)  
DTransform (Transformation v)  
DAnnot a  
DDelay 

DPrim (Prim b v)  
DEmpty 
Null backend
data NullBackend Source
A null backend which does no actual rendering. It is provided
mainly for convenience in situations where you must give a
diagram a concrete, monomorphic type, but don't actually care
which one. See D
for more explanation and examples.
It is courteous, when defining a new primitive P
, to make an instance
instance Renderable P NullBackend where render _ _ = mempty
This ensures that the trick with D
annotations can be used for
diagrams containing your primitive.
HasLinearMap v => Backend NullBackend v  
Monoid (Render NullBackend v)  
data Render NullBackend = NullBackendRender  
data Options NullBackend  
type Result NullBackend v = () 
type D v = Diagram NullBackend v Source
The D
type is provided for convenience in situations where you
must give a diagram a concrete, monomorphic type, but don't care
which one. Such situations arise when you pass a diagram to a
function which is polymorphic in its input but monomorphic in its
output, such as width
, height
, phantom
, or names
. Such
functions compute some property of the diagram, or use it to
accomplish some other purpose, but do not result in the diagram
being rendered. If the diagram does not have a monomorphic type,
GHC complains that it cannot determine the diagram's type.
For example, here is the error we get if we try to compute the
width of an image (this example requires diagramslib
):
ghci> width (image "foo.png" 200 200) <interactive>:8:8: No instance for (Renderable Diagrams.TwoD.Image.Image b0) arising from a use ofimage
Possible fix: add an instance declaration for (Renderable Diagrams.TwoD.Image.Image b0) In the first argument ofwidth
, namely `(image "foo.png" 200 200)' In the expression: width (image "foo.png" 200 200) In an equation forit
: it = width (image "foo.png" 200 200)
GHC complains that there is no instance for Renderable Image
b0
; what is really going on is that it does not have enough
information to decide what backend to use (hence the
uninstantiated b0
). This is annoying because we know that the
choice of backend cannot possibly affect the width of the image
(it's 200! it's right there in the code!); but there is no way
for GHC to know that.
The solution is to annotate the call to image
with the type
, like so:D
R2
ghci> width (image "foo.png" 200 200 :: D R2) 200.00000000000006
(It turns out the width wasn't 200 after all...)
As another example, here is the error we get if we try to compute the width of a radius1 circle:
ghci> width (circle 1) <interactive>:4:1: Couldn't match type `V a0' withR2
In the expression: width (circle 1) In an equation forit
: it = width (circle 1)
There's even more ambiguity here. Whereas image
always returns
a Diagram
, the circle
function can produce any PathLike
type, and the width
function can consume any Enveloped
type,
so GHC has no idea what type to pick to go in the middle.
However, the solution is the same:
ghci> width (circle 1 :: D R2) 1.9999999999999998
Renderable
class Transformable t => Renderable t b where Source
The Renderable type class connects backends to primitives which they know how to render.
render :: b > t > Render b (V t) Source
Given a token representing the backend and a transformable object, render it in the appropriate rendering context.
HasLinearMap v => Renderable (Prim b v) b  The 