I try to create a new route in yesod / haskell with a handler called state, but I get the error empty 'do' block
The steps to reproduce are the following:
stack new haskellYesod yesodweb/simpleyesod add-handler for adding a new handler with the params:
src/Handler/State.hsmodule Handler.State where
import Import
getStateR :: Handler Html
getStateR = do
defaultLayout $ do
$(widgetFile "bla")
templates/bla.hamlet:<h1> BLA!
stack exec yesod develAfter that I get the error:
src/Handler/State.hs:7:21: error: Empty 'do' block
|
7 | defaultLayout $ do
What's happening is that without the TemplateHaskell extension, the syntax $(...) isn't recognized as intended. Instead, it's parsed as a do-block followed by the operator $ and then the expression (...), as if you'd written:
getStateR = do
defaultLayout $ (do $ widgetFile "bla")
^^ empty do-block
You'd see the same problem with the standalone program:
main = do
$(thiswontwork)
which is parsed as main = do $ thiswontwork and generates an Empty 'do' block message, too.
Adding {-# LANGUAGE TemplateHaskell #-} to the top of the State.hs file is enough to fix the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With