-
Notifications
You must be signed in to change notification settings - Fork 9
Closed
Description
Just using the Ema tutorial code,
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
module Main where
import qualified Ema
import Ema (Ema (..))
import Control.Concurrent (threadDelay)
import qualified Data.LVar as LVar
import qualified Ema.CLI
import Text.Blaze.Html5 ((!))
import qualified Text.Blaze.Html5 as H
import qualified Text.Blaze.Html5.Attributes as A
import qualified Text.Blaze.Html.Renderer.Utf8 as RU
data Route
= Index -- Corresponds to /
| About -- Corresponds to /about
deriving (Bounded, Enum, Show)
data Model = Model { speaker :: Text }
instance Ema Model Route where
encodeRoute _model = \case
Index -> "index.html" -- To /
About -> "about.html" -- To /about
decodeRoute _model = \case
"index.html" -> Just Index -- From /
"about.html" -> Just About -- From /about
_ -> Nothing -- Everything else, are bad routes
render :: Ema.CLI.Action -> Model -> Route -> Ema.Asset LByteString
render _emaAction model r = Ema.AssetGenerated Ema.Html . RU.renderHtml $
H.html $ do
H.head $ do
H.title "Basic site"
H.base ! A.href "/" -- This is important.
H.body $ do
H.div ! A.class_ "container" $ do
case r of
Index -> do
H.toHtml $
"You are on the index page. The name is " <> speaker model
routeElem About "Go to About"
About -> do
"You are on the about page. "
routeElem Index "Go to Index"
where
routeElem targetRoute w =
H.a
! A.style "text-decoration: underline"
! A.href (H.toValue $ Ema.routeUrl targetRoute) $ w
main :: IO ()
main = do
Ema.runEma render $ \_act model -> do
LVar.set model $ Model "Ema"
liftIO $ threadDelay maxBound
I'm getting this error:
src/Main.hs:46:13-41: error:
• No instance for (H.ToValue (r0 -> Text))
arising from a use of ‘routeElem’
(maybe you haven't applied a function to enough arguments?)
• In a stmt of a 'do' block: routeElem About "Go to About"
In the expression:
do H.toHtml
$ "You are on the index page. The name is " <> speaker model
routeElem About "Go to About"
In a case alternative:
Index
-> do H.toHtml
$ "You are on the index page. The name is " <> speaker model
routeElem About "Go to About"
|
46 | routeElem About "Go to About"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/Main.hs:49:13-41: error:
• No instance for (H.ToValue (r1 -> Text))
arising from a use of ‘routeElem’
(maybe you haven't applied a function to enough arguments?)
• In a stmt of a 'do' block: routeElem Index "Go to Index"
In the expression:
do "You are on the about page. "
routeElem Index "Go to Index"
In a case alternative:
About
-> do "You are on the about page. "
routeElem Index "Go to Index"
|
49 | routeElem Index "Go to Index"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed, no modules loaded.
�]0;2 errors - ema-template
src/Main.hs:46:13-41: error:
• No instance for (H.ToValue (r0 -> Text))
arising from a use of ‘routeElem’
(maybe you haven't applied a function to enough arguments?)
• In a stmt of a 'do' block: routeElem About "Go to About"
In the expression:
do H.toHtml
$ "You are on the index page. The name is " <> speaker model
routeElem About "Go to About"
In a case alternative:
Index
-> do H.toHtml
$ "You are on the index page. The name is " <> speaker model
routeElem About "Go to About"
|
46 | routeElem About "Go to About"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/Main.hs:49:13-41: error:
• No instance for (H.ToValue (r1 -> Text))
arising from a use of ‘routeElem’
(maybe you haven't applied a function to enough arguments?)
• In a stmt of a 'do' block: routeElem Index "Go to Index"
In the expression:
do "You are on the about page. "
routeElem Index "Go to Index"
In a case alternative:
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels