Diagrams/Migrate0.5
From HaskellWiki
(0.4 > 0.5 migration) 
(note a few more migrations) 

Line 61:  Line 61:  
If you want the old behavior, simply perform an alignment on the first diagram before combining. That is, replace <code>beside v d1 d2</code> by <code>beside v (align v d1) d2</code>. If <code>d1</code> and <code>d2</code> are the same width the same effect can be achieved by first combining and then centering. 
If you want the old behavior, simply perform an alignment on the first diagram before combining. That is, replace <code>beside v d1 d2</code> by <code>beside v (align v d1) d2</code>. If <code>d1</code> and <code>d2</code> are the same width the same effect can be achieved by first combining and then centering. 

+  
+  == 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 <code>AnnDiagram</code> to <code>QDiagram</code> everywhere it occurs. 

+  
+  == Additional Semigroup constraints == 

+  
+  In some places diagrams now requires a <code>Semigroup</code> constraint in addition to <code>Monoid</code> (ideally <code>Monoid</code> would have <code>Semigroup</code> as a superclass...). If you get an error about "could not deduce <code>Semigroup</code> constraint" you probably just need to add one. 
Revision as of 03:27, 6 March 2012
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.