我正在使用Haskell并使用Chart模块。在active GTK窗口中没有呈现文档。所以我试着用自己的:
import Graphics.Rendering.Chart.Easy
import Graphics.Rendering.Chart.Gtk
signal :: [Double] -> [(Double,Double)]
signal xs = [ (x,(sin (x*3.14159/45) + 1) / 2 * (sin (x*3.14159/5))) | x <- xs ]
main = renderableToWindow def 300 300 $ do
layout_title .= "Amplitude Modulation"
setColors [opaque blue, opaque red]
plot (line "am" [signal [0,(0.5)..400]])
plot (points "am points" (signal [0,7..400]))但是这是不正确的,因为ghc -o main main.hs返回:
[1 of 1] Compiling Main ( main.hs, main.o )
main.hs:7:8:
Couldn't match expected type ‘Control.Monad.Trans.State.Lazy.StateT
(Layout Double Double)
(Control.Monad.Trans.State.Lazy.State CState)
()
-> t’
with actual type ‘IO ()’
Relevant bindings include main :: t (bound at main.hs:7:1)
The first argument of ($) takes one argument,
but its type ‘IO ()’ has none
In the expression:
renderableToWindow def 300 300
$ do { layout_title .= "Amplitude Modulation";
setColors [opaque blue, opaque red];
plot (line "am" [signal [0, (0.5) .. 400]]);
plot (points "am points" (signal [0, 7 .. 400])) }
In an equation for ‘main’:
main
= renderableToWindow def 300 300
$ do { layout_title .= "Amplitude Modulation";
setColors [opaque blue, ....];
plot (line "am" [signal ...]);
.... }那么现在我的问题是:如何做出正确的GTK渲染?
发布于 2015-10-20 16:42:18
renderableToWindow有.
renderableToWindow :: Renderable a -> Int -> Int -> IO ()..。所以它不把你想要传递的EC计算作为最后一个参数。我认为最简单的解决方案是使用toWindow,它将在默认状态下运行EC计算,将其结果转换为Renderable并将其传递给renderableToWindow。
toWindow :: (Default r, ToRenderable r) => Int -> Int -> EC r () -> IO ()
main = toWindow 300 300 $ do
layout_title .= "Amplitude Modulation"
setColors [opaque blue, opaque red]
plot (line "am" [signal [0,(0.5)..400]])
plot (points "am points" (signal [0,7..400]))https://stackoverflow.com/questions/33241799
复制相似问题