Haskell Diagrams Output without commandline

我与影子孤独终老i 提交于 2019-12-11 19:27:21

问题


I have one question: I know how to output svg file with a help of ghc --make Strukturine.hs command in Terminal. As I understood it uses import Diagrams.Backend.SVG.CmdLine . Is it possible somehow load Strukturine.hs file with the help of :load Strukturine.hs in terminal and then just put the name of function for example: strukturine. That function should output a scheme/picture (to svg file).

The beginning of Strukturine.hs file looks like this

{-# LANGUAGE NoMonomorphismRestriction #-}

module Strukturine where

import Diagrams.Prelude

import Diagrams.Backend.SVG.CmdLine

import Data.Maybe (fromMaybe)

import Data.Char

import Input

import qualified Input(getNumber) --other module

main = mainWith(strukturine :: Diagram B R2)

回答1:


You can use the function renderSVG from Diagrams.Backend.SVG.

renderSVG :: FilePath -> SizeSpec2D -> Diagram SVG R2 -> IO ()

For example to render a 400x400 svg:

import Diagrams.Backend.SVG (renderSVG)

outputFile :: FilePath
outputFile = "strukturine.svg"

dimensions :: SizeSpec2D
dimensions = mkSizeSpec (Just 400) (Just 400)

strukturineDiagram :: Diagram SVG R2

strukturine = do renderSVG outputFile dimensions strukturineDiagram

See http://projects.haskell.org/diagrams/haddock/Diagrams-Backend-SVG.html#v:renderSVG

And for more specific rendering, see: http://projects.haskell.org/diagrams/doc/cmdline.html



来源:https://stackoverflow.com/questions/23083528/haskell-diagrams-output-without-commandline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!