갈루아의 반서재

하스켈 Yesod 페이지를 추가하는 튜토리얼을 진행하는 중 다음과 같이 Echo.hs:6:48: error: parse error on input ‘{’ 을 만나는 경우 다음과 같이 처리한다.


src/Echo.hs 

1
2
3
4
5
6
module Handler.Echo where
 
import Import
 
getEchoR :: String -> Handler Html
getEchoR theText = defaultLayout [whamlet|<h1>#{theText}|]
cs


상기 소스를 rebuild 하면 다음과 같은 에러 발생

1
2
3
4
5
6
7
[11 of 12] Compiling Handler.Echo     ( src/Handler/Echo.hs, .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/Handler/Echo.o )
 
/src/Handler/Echo.hs:6:48: error: parse error on input ‘{’
 
--  While building package blackbriar-0.0.0 using:
      /root/.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:blackbriar --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1
cs


Echo.hs 의 6번째 라인의 [whamlet|<h1>#{theText}|] 는 quasiquote 구문으로, QuasiQuotes GHC extension 이 사용가능해야 한다. 

가장 간단하게 이 에러를 해결하는 방법은  {-# LANGUAGE QuasiQuotes #-} 라는 pragma 를 해당 .hs 파일의 최상단에 추가하는 것이다 (경우에 따라서는 프로젝트 전반에 적용되도록 Cabal 파일에 추가할 수도 있다).