Haskell Gnuplot 不响应标题功能

Haskell Gnuplot not responding to title function

我正在尝试为 Haskell 中使用 Gnuplot 制作的绘图添加标题。虽然该程序在它创建的 stand-alone window 中生成了一个图形,但我似乎无法让它响应标题函数。我是不是用错了title函数?

我正在使用 Stack,

 - only "-gnuplot" added to the "dependencies:" section of package.yaml
 - resolver: lts-15.7 in an unmodified stack.yaml.

在计算机上 运行 Linux Mint 19。 pop-up window 的代码和屏幕截图是:

module Main where

import Graphics.Gnuplot.Advanced
import Graphics.Gnuplot.Plot.TwoDimensional as P2D
import Graphics.Gnuplot.Graph.TwoDimensional as G2D
import Graphics.Gnuplot.Terminal.X11 as X11

zeroToTen = [0.0, 0.1 .. 10.0 :: Double]

main :: IO ()
main = do
  plot (X11.title "My Title" X11.cons) (P2D.function G2D.lines zeroToTen sin)
  _  <- getLine
  return ()

这是 gnuplot(软件包)中的错误。以下是代码块,其中 X11 终端的选项内置到 gnuplot-可解析的命令行参数中:

文件:X11.hs

-- Part of a record update, hence the trailing comma
Terminal.options =
     "x11" :
     catMaybes (
           (fmap quote $ title_ term) :
        (fmap (formatBool "persist") $ persist_ term) :
        []),

在倒数第三行,term 记录的 title_ :: Maybe String 字段被 quote 函数(只是 show 的别名)用引号括起来。问题是为了被 gnuplot 解析,还应该在前面加上 title see manual). Until it gets fixed, you can always configure gnuplot as a local package 并从那里构建它。

这是修复(X11.hs 的第 43 行):

(fmap (("title " ++) . quote) $ title_ term) :

顺便说一句,有一个更优化的导入包的方法。写作 import X as Y 表示:"import everything into the global namespace, but also give me Y as an alias for the imported symbols"。更好的方法是 import qualified X as Y,它将导入的模块隔离到 Y 命名空间。

最后的笔记 如果您尝试自己构建 gnuplot,您会发现 gnuplot 无法编译,因为 GHC 8.4 中的 "Semigroup-Monoid" 提案导致缺少几个 Semigroup 实例。解决这个问题的方法是简单地添加一个 Semigroup 实例,它引用 Monoid 实例中的 mappend 方法:

import Data.Semigroup
instance Semigroup Script where
  (<>) = mappend