Diagrams/Migrate0.5
From HaskellWiki
This page describes API changes between diagrams 0.4 and 0.5, along with explanations of how to migrate to the new 0.5 API.
Contents 
1 R2 and P2 are now abstract
The biggest change to the API between versions 0.4 and 0.5 is that the R2
and P2
types (representing 2D vectors and points, respectively) are now abstract. R2
used to be a synonym for (Double, Double)
but this is no longer the case. Also, the constructor P
for points is no longer exported.
You can use the functions
r2 :: (Double, Double) > R2 unr2 :: R2 > (Double, Double) p2 :: (Double, Double) > P2 unp2 :: P2 > (Double, Double)
to convert between pairs of Double
s and vectors or points. For example, if you had
beside (4,2) d1 d2
change it to
beside (r2 (4,2)) d1 d2
If you had
fromOffsets [(2,1), (3,5), (2,0)]
change it to
fromOffsets . map r2 $ [(2,1), (3,5), (2,0)]
Note you can still use unitX, unitY, unit_X, unit_Y :: R2
.
If you had some code patternmatching on vectors or points, the ViewPatterns
extension comes in handy: change
foo :: R2 > ... foo (x,y) = ... x ... y ... bar :: P2 > ... bar (P (x,y)) = ... x ... y ...
to
{# LANGUAGE ViewPatterns #} foo :: R2 > ... foo (unr2 > (x,y)) = ... x ... y ... bar :: P2 > ... bar (unp2 > (x,y)) = ... x ... y ...
To convert a vector v
to a point, use origin .+^ v
. To convert a point p
to a vector, use p .. origin
.
2 roundedRect
The roundedRect
function now takes two Double
arguments instead of an R2
argument, to be more consistent with rect
. If you had something like roundedRect (2,3) 0.2
, just change it to roundedRect 2 3 0.2
.
3 circlePath
The circlePath
function has been removed; you should be able to simply replace it with circle
.
4 Semantics of beside
The semantics of beside
and hence also terms ()
and (===)
, which are implemented in terms of besideis now different. In particular, the local origin of beside v d1 d2
is now the local origin of d1
rather than the point of tangency between d1
and d2
. This has several advantages, namely

beside v
,()
, and(===)
are now associative  The new semantics is more consistent with the semantics of
cat
.
If you want the old behavior, simply perform an alignment on the first diagram before combining. That is, replace beside v d1 d2
by beside v (align v d1) d2
. If d1
and d2
are the same width the same effect can be achieved by first combining and then centering.
5 AnnDiagram renamed QDiagram
This change was made to be consistent with referring to the monoidal parameter as a "query" rather than an "annotation". Simply change AnnDiagram
to QDiagram
everywhere it occurs.
6 Additional Semigroup constraints
In some places diagrams now requires a Semigroup
constraint in addition to Monoid
(ideally Monoid
would have Semigroup
as a superclass...). If you get an error about "could not deduce Semigroup
constraint" you probably just need to add one.