在ghci中设置选项

3
我正在尝试使用字符串插值,就像这里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
1个回答

6

单独模块中启用的语言特性无法传播到 ghci 会话中。您需要重新启用它们,即执行 :set -XQuasiQuotes


顺便提一下,您应该使用以下方式启用语言特性:

{-# LANGUAGE QuasiQuotes #-}

Haskell源文件中的语法。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接