Problems with Haskell/Hamlet

147 Views Asked by At

I'm a beginner at haskell and I'm trying to use hamlet, but I'm no getting the syntax right. When I use this Code:

{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
module Handler.Index where

import Import
import Network.HTTP.Types.Status
import Database.Persist.Postgresql

getIndexR :: Handler Html
getIndexR = defaultLayout $ do
addStylesheet $ StaticR bootstrap_css
[hamlet|
        $doctype 5
        <html>
            <head>

            <body>

        |]

[cassius|
        .classe
            background: red;
        |]

I get this error:

romefeller:~/workspace/yesodvazio (master) $ stack build && stack exec 
aulahaskell
aulahaskell-0.0.0: build (lib + exe)
Preprocessing library aulahaskell-0.0.0...
[8 of 9] Compiling Handler.Index    ( src/Handler/Index.hs, .stack-
work/dist/x86_64-linux/Cabal-1.24.2.0/build/Handler/Index.o )

/home/ubuntu/workspace/yesodvazio/src/Handler/Index.hs:18:17: error: parse 
error on input ‘<’

--  While building package aulahaskell-0.0.0 using:
  /home/ubuntu/.stack/setup-exe-cache/x86_64-linux/Cabal-
simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-
linux/Cabal-1.24.2.0 build lib:aulahaskell exe:aulahaskell --ghc-options " -
ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1

What am I missing? Do I need to import any librarie or something?

1

There are 1 best solutions below

7
K. A. Buhr On

You need to enable:

{-# LANGUAGE QuasiQuotes #-}

instead of TemplateHaskell or else GHC tries to parse your [hamlet|...|] clause as if it was the start of a list comprehension, like this:

[ hamlet | hamlet <- ["alas", "poor", "yorick"] ]
^^^^^^^^^^ -- GHC thinks you're starting to write this
           -- and can't parse the rest.

(The TemplateHaskell extension only enables quasiquote syntax for the specific quasiquote types that it recognizes, and tries to parse everything else as list comprehension syntax.)