Tutorial example fails with "No instance for (H.ToValue ... arising from a use of 'routeElem'" #52
Unanswered
JonathanReeve
asked this question in
Q&A
Replies: 1 comment 1 reply
-
|
@JonathanReeve Looks like you are using Ema's You have two options:
The second option is ideal, and you can use the history link above to know the series of changes required. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
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 maxBoundI'm getting this error:
Beta Was this translation helpful? Give feedback.
All reactions