The first half of my project was refactoring diagrams-lib to not
hard-code Double; this is done except for renaming R2ISh to R2 and
fixing the backends. See the generalize-double branch and issue #50 in
diagrams-lib.
The second half of my project is finding a constraint solver and
connecting diagrams to it in a useful way. I've read through all of
Hackage and besides finding some interesting libraries (there are 4
color packages: colors, colour, prizm, and wright; and 'tau' and
'splines' packages that diagrams doesn't use), I created a list of
possible constraint solvers.
The first category are SMT solvers; although they're probably not a
great fit for the project, there does seem to be somewhat
well-maintained bindings for Yices, Z3, and CVC4. The Yices page
claims it can solve sets of linear constraints.
But if all I have are sets of linear constraints, and I want to solve
them with an SMT solver, then I could just use linearEqSolver, which
wraps the SMT solvers and gives me a single function
solveRationalLinearEqs. Or I could use the linear programming thing of
toysolver, or implement a more complex linear solver like the
Cassowary algorithm (used in Apple's Cocoa UI kit for laying out
buttons and other elements).
If we go to nonlinear stuff, then there are still a few options left.
There are implements of nonlinear optimization, namely
hmatrix-quadprogpp, lagrangian, levmar and nonlinear-optimization,
almost all of which can optimize in the presence of linear constraints
as well. It's a simple nearest-extrema search though so I'm not
certain how well it can lay out diagrams.
The final library I've found is GECODE, "generic constraint
development environment", which allows specifying all of the above:
arbitrary linear constraints, arbitrary nonlinear constraints, and
arbitrary nonlinear optimization criteria. I haven't really delved
into the source code too deeply, so maybe the API promises more than
it can deliver. There's also the issue of the bindings
(monadiccp-gedcode), which are to version 3.1.0 (released in 2009)
instead of to the latest version (4.2.1, released last year). I've
sent an email to the maintainer on Monday but no response yet.
Anyways, dear diagrams-discuss, which solver should I use? Did I miss
any in my review of Hackage, or are there some non-yet-uploaded
solvers floating around on Github?
Finally, there is the question of "usefulness"; I asked my mentor for
a simple example of when you would need to use constraint solving in
diagrams, and he was unable to think of one off the top of his head. I
searched the web and found
http://www.skybluetrades.net/blog/posts/2011/11/14/constraints-intro.html,
whose reasoning was roughly "I used AutoDesk’s Mechanical Desktop for
a work project and it was really cool and a Haskell clone would be
even cooler", but at least he had an example. Cassowary has spawned a
whole literature on UI layout algorithms, which I've been slowly
working through; they're OK but very focused on interactive layout. In
terms of diagrams this is only relevant for animations, which do seem
to be under-developed so maybe I should work on that too?
I get to discuss all of this with bergey tomorrow at 17:00 UTC (i.e.,
in 12 hours), so feel free to join us in #diagrams then.
-- Allan Gardner