2

With "image" diagrams I can just pass a function that expects parameters (here pDiag) to mainWith and append neccessary parameters to the command like so:
stack exec circle-diagram-exe -- -o circle.png -w 800 9

module DiagramsWithParameters where

import Diagrams.Prelude
import Diagrams.Backend.Cairo.CmdLine

--main = mainWith pDiag
main = mainWith pAnimation

pDiag :: Double -> Diagram B
pDiag d = circle d # fc gold

pAnimation :: Int -> [(Diagram B, Int)]
pAnimation r = replicate r ((circle 0.95 # fc gold), 1)

However with animations I cannot even build:

    • No instance for (Diagrams.Backend.CmdLine.ToResult
                         [(QDiagram B V2 Double Any, Int)])
        arising from a use of ‘mainWith’
    • In the expression: mainWith pAnimation
      In an equation for ‘main’: main = mainWith pAnimation
  |
7 | main = mainWith pAnimation
  |        ^^^^^^^^^^^^^^^^^^^

How can I support command line arguments for my animations?

duplode
  • 33,731
  • 7
  • 79
  • 150
peer
  • 4,171
  • 8
  • 42
  • 73
  • While I haven't tried running it to be sure, it seems `[(Diagram B, Int)]` has [a `Mainable` instance](https://hackage.haskell.org/package/diagrams-cairo-1.4.1/docs/Diagrams-Backend-Cairo-CmdLine.html#section.orphans) but not a [`ToResult`](http://hackage.haskell.org/package/diagrams-lib-1.4.2.2/docs/Diagrams-Backend-CmdLine.html#t:ToResult) one, with both being required by the type of `mainWith`. It's not ideal, but it might make sense to work around that by supplying the missing `ToResult` instance as an orphan. – duplode Jan 23 '21 at 14:01

0 Answers0