rogergl
rogergl

Reputation: 3781

Why is this indentation wrong?

This code gives the following compile error:

Error:(17, 1) ghc: parse error (possibly incorrect indentation or mismatched brackets)

but if I remove

module Main where

it works. Since I'm just starting to use Haskell I would like to know why ?

module Main where

{-# LANGUAGE QuasiQuotes #-}

import Text.Hamlet (shamlet)
import Text.Blaze.Html.Renderer.String (renderHtml)
import Data.Char (toLower)
import Data.List (sort)

data Person = Person
    { name :: String
    , age  :: Int
    }

main :: IO ()
main = putStrLn $ renderHtml [shamlet|
<p>Hello, my name is #{name person} and I am #{show $ age person}.
<p>
    Let's do some funny stuff with my name: #
    <b>#{sort $ map toLower (name person)}
<p>Oh, and in 5 years I'll be #{show ((+) 5 (age person))} years old.
|]
  where
    person = Person "Michael" 26

Upvotes: 3

Views: 131

Answers (1)

jamshidh
jamshidh

Reputation: 12070

The line

{-# LANGUAGE QuasiQuotes #-}

is supposed to come on the first line in the program, before

module Main where

These language extensions are supposed to be meta information, external to the program itself (they can also be included as command line options to ghc).

Upvotes: 10

Related Questions