此代码提供以下编译错误:
Error:(17, 1) ghc: parse error (possibly incorrect indentation or mismatched brackets)
但如果我删除
module Main where
它有效。由于我刚刚开始使用Haskell,我想知道为什么?
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
答案 0 :(得分:10)
该行
{-# LANGUAGE QuasiQuotes #-}
应该出现在程序的第一行,
之前module Main where
这些语言扩展应该是元信息,在程序本身外部(它们也可以作为命令行选项包含在ghc中)。