Reputation: 89043
I'm trying to compile 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
And I'm running into an error:
% 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 `{'
So it seems like the ghc's having an issue with the jmacro
quasi-quoter
expression. I'm not sure whether this is because there's a bug in the code, or
whether I'm doing something wrong compiling it.
I'm using ghc 7.6.3, and cabal 1.20.0.1 with this cabal file:
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
Upvotes: 4
Views: 149
Reputation: 89043
Figured it out from reading Quasiquotation right about when Ørjan Johansen pointed it out to me - I needed to put {-# LANGUAGE QuasiQuotes #-}
at the top of the example code.
It compiles and mostly works now (the server doesn't give a Content-Type
header when responding with the page, which makes it look wonky in my browser), but other than that, success.
Upvotes: 1