我正在尝试使用字符串插值,就像这里http://hackage.haskell.org/package/interpolate-0.2.0/docs/Data-String-Interpolate.html中所示。
具体来说,
>>> :set -XQuasiQuotes
>>> import Data.String.Interpolate
>>> let name = "Marvin"
>>> putStrLn [i|name: #{name}|]
name: Marvin
如果在 ghci 中运行此命令,则可以正常工作。同时,如果按照此处所示的方法编写文件,也可以正常工作 https://downloads.haskell.org/~ghc/7.6.3/docs/html/users_guide/ch04s02.html
{-# OPTIONS_GHC -XQuasiQuotes #-}
import Data.String.Interpolate
main = do
let name = "Marvin"
putStrLn [i|name: #{name}|]
但如果我仅使用选项和导入文件,并在ghci中运行命令,我会遇到一个错误 parse error on input'#'
-- in file example.hs
{-# OPTIONS_GHC -XQuasiQuotes #-}
import Data.String.Interpolate
-- in GHCi, ghci example.hs, then run
> let name = "Marvin"
> putStrLn [i|name: #{name}|]
`parse error on input'#'`
what's happening here and why can't i run the command in ghci?
thanks