我正在使用Haskell和使用箭头语言扩展的Yampa FRP库。
如何在SF中执行简单的putStrLn?
mySF = proc x -> do
y <- identity -< x*x
putStrLn "Hello World!" ++ show y
returnA -< y
箭头语法抱怨表达式不是箭头(当然),但即使使用箭头我也没有输出
output <- identity -< putStrLn "Hello World!"
答案 0 :(得分:6)
在尝试阅读FRP论文时,我只和Yampa玩过一段时间,但据我所知,这与你在Yampa IO
的工作方式完全不同。相反,您使用SF a b
函数“动画”reactimate
,该函数将b -> IO ()
类型的函数作为其第二个参数。这个函数就像你的putStrLn
之类的东西一样,以及程序所做的任何其他类型的渲染。
"Yampa Arcade"论文的“动画信号函数”部分很好地解释了reactimate
的工作原理。
答案 1 :(得分:5)
以下是Yampa的完整Hello World示例。
{-# LANGUAGE Arrows #-} import FRP.Yampa main = reactimate initialize input output process initialize = return "Hello World!" input _ = return (0.0, Nothing) output _ x = putStrLn x >> return True process = identity