我正在尝试编译some example code from Network.JMacroRPC.Snap:
module Main where
import Network.JMacroRPC.Snap
import Snap.Http.Server
import Snap.Core
import Language.Javascript.JMacro
import Control.Concurrent
import Control.Monad.Trans
import Network.JMacroRPC.Base
import Text.XHtml hiding(dir)
import qualified Data.Text as T
jsScript f = script (primHtml f) ! [thetype "text/javascript"]
jsScript' = jsScript . show . renderJs
testPage = mkConversationPageNoCulling pageFun (newMVar (1::Int)) jRpcs
where pageFun :: JStat -> Snap ()
pageFun js = writeText $ T.pack $ show $
(header << [script ! [src "https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"] << noHtml]) +++
jsScript' js +++
jsScript' ([jmacro|$(\
{
var b = $("<button>click me!</button>");
$("body").append(b);
b.click(\ {
var c = getCounter();
alert ("counter is: " + c);
});
});
|]);
jRpcs = [getCounterRPC]
getCounterRPC =
toJsonConvRPC "getCounter" $ \s -> (liftIO $ retRight =<< modifyMVar s (\i -> return (i+1,i)) :: Snap (Either String Int))
retRight :: a -> IO (Either String a)
retRight = return . Right
main = quickHttpServe =<< testPage
我遇到了错误:
% cabal build
Building jmacro-snap-example-0.1.0.0...
Preprocessing executable 'jmacro-snap-example' for
jmacro-snap-example-0.1.0.0...
[1 of 1] Compiling Main ( Main.hs, dist/build/jmacro-snap-example/jmacro-snap-example-tmp/Main.o )
Main.hs:22:38: parse error on input `{'
因此,似乎ghc对jmacro
准引号有疑问
表达。我不确定这是因为代码中有错误,或者
我是否做错了编译。
我使用ghc 7.6.3和cabal 1.20.0.1使用此cabal文件:
name: jmacro-snap-example
version: 0.1.0.0
build-type: Simple
cabal-version: >=1.10
executable jmacro-snap-example
main-is: Main.hs
other-extensions: TemplateHaskell
build-depends: base >=4.6 && <4.7, jmacro-rpc-snap >=0.3 && <0.4, snap-server >=0.9 && <0.10, snap-core >=0.9 && <0.10, jmacro >=0.6 && <0.7, mtl >=2.1 && <2.2, jmacro-rpc >=0.3 && <0.4, xhtml >=3000.2 && <3000.3, text >=0.11 && <0.12
default-language: Haskell2010
答案 0 :(得分:1)
从Quasiquotation开始,直到Ørjan Johansen pointed it out to me时才知道 - 我需要将{-# LANGUAGE QuasiQuotes #-}
放在示例代码的顶部。
它编译并且主要是现在可以正常工作(服务器在回复页面时没有给出Content-Type
标题,这使得它在我的浏览器中看起来很糟糕),但其他比那更成功。