Haskell Diagrams error: "No diagram selected."

时间:2016-10-15 17:04:02

标签: haskell haskell-diagrams

I am attempting to create a set of diagrams, using the following main function:

main = mainWith [("here0", myDiagram), ("here1", myDiagram)]

and am getting the following error:

No diagram selected.
Available diagrams:
  here0 here1

Any idea what this error means?


More details:

My "myDiagram" has type:

myDiagram :: Diagram B

and the program works correctly when the main function is instead:

main = mainWith myDiagram

EDIT:

Thanks for the comments. I looked at the linked command-line tutorial and attempted to follow it as closely as possible (including specifying the -s option), but am still running into the same issue. Here's exactly what I did:

Created a file "Animation.hs":

{-# LANGUAGE NoMonomorphismRestriction #-}

import Diagrams.Prelude 
import Diagrams.Backend.SVG.CmdLine

main = mainWith [("myBlue", myBlue), ("myGreen", myGreen)]

myBlue :: Diagram B
myBlue = circle 1 # lw none # fc blue

myGreen :: Diagram B
myGreen = circle 1 # lw none # fc green

Compiled it via:

ghc --make Animation.hs

Displayed the available diagrams to render, with:

./Animation --list

which, as expected, returned:

Available diagrams:
  myBlue myGreen

But finally, attempting to generate one of the .svg's via:

./Animation -o out.svg -w 400 -s myBlue

returned:

No diagram selected.
Available diagrams:
  myBlue myGreen

I feel like there must be something simple that I'm missing but cannot seem to find it -- I am specifying a listed available diagram with "-s myBlue".

1 个答案:

答案 0 :(得分:2)

If you use mainWith in this way, you have to choose which of the diagrams will be rendered through the -S command line option. Quoting the official comand-line tutorial:

If we have multiple diagrams with names we can use mainWith to give an interface that allows the selection of a particular diagram by name.

> -- Multiple
>
> d1, d2, d3 :: Diagram SVG V2 Double
> ...
>
> main = mainWith [("First", d1),("Second", d2),("Third", d3)]

The --list option just lists the available diagrams to render and the -S selection option takes a name and renders the associated diagram with the standard options.

$ ./Multiple --list
Available diagrams:
  First Second Third
$ ./Multiple -o d1.svg -w 100 -S First

Note that the option used is -S, and not -s like in the tutorial (as of 2016/10/25). The option had been changed due to this issue, but the change wasn't reflected in the tutorial yet (a patch fixing it was accepted though, so it should become correct anytime soon). The help message of the program is correct though:

$ stack --resolver=lts-7.2 exec -- runhaskell Dag.hs -?
Dag.hs

Usage: Dag.hs [-?|--help] [-w|--width WIDTH] [-h|--height HEIGHT]
              [-o|--output OUTPUT] [-l|--loop] [-s|--src ARG]
              [-i|--interval INTERVAL] [-p|--pretty] [-S|--selection NAME]
              [-L|--list]
  Command-line diagram generation.

Available options:
  -?,--help                Show this help text
  -w,--width WIDTH         Desired WIDTH of the output image
  -h,--height HEIGHT       Desired HEIGHT of the output image
  -o,--output OUTPUT       OUTPUT file
  -l,--loop                Run in a self-recompiling loop
  -s,--src ARG             Source file to watch
  -i,--interval INTERVAL   When running in a loop, check for changes every
                           INTERVAL seconds.
  -p,--pretty              Pretty print the SVG output
  -S,--selection NAME      NAME of the diagram to render
  -L,--list                List all available diagrams