Search code examples
haskellyesodparse-error

Basic Yesod Hello World! giving me parse error


I am beginning to learn Yesod through the book Developing Web Applications with Haskell and Yesod. The first thing the book has you do after installing a few requirements is write a Hello World! Despite copying the program verbatim from the book, I am getting a parse error. As a bit of background, I have no experience in web development, and my knowledge of Haskell is pretty much contained to Learn You a Haskell, so I am quite lost.

Here is the said code:

-- hello world with Yesod

{-# LANGUAGE TemplateHaskell, TypeFamilies, QuasiQuotes, MultiParamTypeClasses,
    OverloadedStrings #-}

import Yesod

data HelloWorld = HelloWorld

mkYesod "HelloWorld" [parseRoutes |
/ HomeR GET
|]

instance Yesod HelloWorld

getHomeR :: Handler RepHtml
getHomeR = defaultLayout [whamlet | Hello World! |]

main :: IO()
main = warpDebug 3000 HelloWorld

The compiler is telling me this:

C:\Haskell\Yesod>runhaskell helloWorld.hs

helloWorld.hs:11:1:
    parse error (possibly incorrect indentation or mismatched brackets)

Solution

  • I got your file to load (with warnings) by deleting the spaces before the pipes in the quasiquoter lines, so [parseRoutes| instead of [parseRoutes | and [whamlet| instead of [whamlet |.