Haskell Diagrams输出没有命令行 [英] Haskell Diagrams Output without commandline

查看:140
本文介绍了Haskell Diagrams输出没有命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题:我知道如何在终端中借助 ghc --make Strukturine.hs 命令输出svg文件。据我了解,它使用导入Diagrams.Backend.SVG.CmdLine 。是否可以通过的帮助以某种方式加载Strukturine.hs文件:在终端中加载Strukturine.hs ,然后将函数名称例如:strukturine。该功能应输出一个方案/图片(以svg文件)。



Strukturine.hs文件的开头看起来像这样

  { - #LANGUAGE NoMonomorphismRestriction# - } 

模块Strukturine其中

import Diagrams.Prelude

import Diagrams.Backend.SVG.CmdLine

导入Data.Maybe(fromMaybe)

导入Data.Char

导入输入

导入限定输入(getNumber) - 其他模块

main = mainWith(strukturine :: Diagram B R2)


解决方案

您可以使用Diagrams.Backend.SVG中的renderSVG函数。

  renderSVG :: FilePath - > SizeSpec2D  - >图表SVG R2  - > IO()

例如,渲染一个400x400的svg:

  import Diagrams.Backend.SVG(renderSVG)

outputFile :: FilePath
outputFile =strukturine.svg

dimensions :: SizeSpec2D
dimensions = mkSizeSpec(只有400)(只有400)

strukturineDiagram :: Diagram SVG R2

strukturine = do renderSVG outputFile维度strukturineDiagram

请参阅 http://projects.haskell.org/diagrams/haddock/Diagrams-Backend-SVG.html#v:renderSVG p>

更具体的渲染请参阅: http://projects.haskell.org/diagrams/doc/cmdline.html


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)

解决方案

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

这篇关于Haskell Diagrams输出没有命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆