Re: [Yesod] [ Haskell and Yesod ] parse error from "Hello World" ( Chapter 3. Basics)

240 views
Skip to first unread message

François Gannaz

unread,
Aug 7, 2012, 6:21:49 AM8/7/12
to yeso...@googlegroups.com
Hi

I'm quite new to Yesod myself, so someone will amend this if I'm wrong.

The syntax "[parseRoutes| ... |]" isn't part of the Haskell language,
it's a quasi-quote which is only allowed through an extension called
"Template Haskell" (TH).

You need to activate some compiling options in order to activate TH.
This can be done on the command line, but the simplest way is to add the
following line at the beginning of your file:

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

So the complete file becomes:

~~~~
{-# LANGUAGE TemplateHaskell, QuasiQuotes, OverloadedStrings, MultiParamTypeClasses, TypeFamilies #-}
import Yesod

data HelloWorld = HelloWorld

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

instance Yesod HelloWorld

getHomeR :: Handler RepHtml
getHomeR = defaultLayout [whamlet|Helloworld!|]

main :: IO ()
main = warpDebug 3000 HelloWorld
~~~~

Hope that helps
--
François


On 2012-08-07, "Sok H. Chang" <sha...@gmail.com> wrote:
> I'm new to Haskell & Yesod.
> If this question border you, sorry for this...
> How can I fix my error?
>
> I got error message.
> $ runhaskell helloworld.hs
> helloworld.hs:6:23: parse error on input `/'
>
> helloworld.hs
> -----------------------------------------------------------------
> import Yesod
>
> data HelloWorld = HelloWorld
>
> mkYesod "HelloWorld" [parseRoutes|
> / HomeR GET
> |]
>
> instance Yesod HelloWorld
> getHomeR:: Handler RepHtml
> getHomeR = defaultLayout [whamlet|Helloworld!|]
>
> main :: IO ()
> main = warpDebug 3000 HelloWorld

Sok H. Chang

unread,
Aug 8, 2012, 1:46:42 AM8/8/12
to yeso...@googlegroups.com
Dear, François

Thank you so much !
I must learn about TH...

Thank you again,
and Have a nice day!

Sincerely, Sok Chang

2012년 8월 7일 화요일 오후 7시 21분 49초 UTC+9, François Gannaz 님의 말:
Reply all
Reply to author
Forward
0 new messages