Haskell 增加「;宽度“;ghci公司
当GHCI中的输出线过长时,会断开:Haskell 增加「;宽度“;ghci公司,haskell,ghci,Haskell,Ghci,当GHCI中的输出线过长时,会断开: > :i bar bar :: Lens' (Foo a0) Int -- Defined at NewType_makeLenses.hs:7:1 > :i baz baz :: Lens (Foo a0) (Foo a1) a0 a1 -- Defined at NewType_makeLenses.hs:7:1 有没有办法设置线条的最大长度?有三个选项可以控制 您正在寻找-dppr cols。其默认值为100。您可以在调用GH
> :i bar
bar :: Lens' (Foo a0) Int -- Defined at NewType_makeLenses.hs:7:1
> :i baz
baz :: Lens (Foo a0) (Foo a1) a0 a1
-- Defined at NewType_makeLenses.hs:7:1
有没有办法设置线条的最大长度?有三个选项可以控制 您正在寻找
-dppr cols
。其默认值为100
。您可以在调用GHCi或使用:set
时将其设置为任何其他值
方案比较
不带-dppr cols
使用-dppr-cols140
带:设置-dppr-cols140
奖金:我是怎么找到这个的?
我没有查看标志,而是查看了GHC的源代码:
$ git clone --depth=1 https://github.com/ghc/ghc.git && cd ghc
接下来,我查找以定义的开头的字符串:
$ grep -C2 "\"Defined" -r . --exclude-dir=testsuite
./compiler/basicTypes/Name.hs-ppr_z_occ_name occ = ztext (zEncodeFS (occNameFS occ))
./compiler/basicTypes/Name.hs-
./compiler/basicTypes/Name.hs:-- Prints (if mod information is available) "Defined at <loc>" or
./compiler/basicTypes/Name.hs:-- "Defined in <mod>" information for a Name.
./compiler/basicTypes/Name.hs-pprDefinedAt :: Name -> SDoc
./compiler/basicTypes/Name.hs:pprDefinedAt name = text "Defined" <+> pprNameDefnLoc name
./compiler/basicTypes/Name.hs-
./compiler/basicTypes/Name.hs-pprNameDefnLoc :: Name -> SDoc
Outputable.hs
包括printForUser
,它与Pretty
中的printDoc
一起使用pprcoldflags
,定义为
printDoc :: Mode -> Int -> Handle -> Doc -> IO ()
-- printDoc adds a newline to the end
printDoc mode cols hdl doc = printDoc_ mode cols hdl (doc $$ text "")
而pprCol
是在compiler/main/DynFlags.hs
中定义的,它对应于-dppr cols
。您只需通过GHC:grep
即可。谢谢。我的工具中包含了这个选项:)
$ ghci NewType_makeLenses.hs
[1 of 1] Compiling Main ( NewType_makeLenses.hs, interpreted )
Ok, modules loaded: Main.
> :set -dppr-cols140
> :i bar
bar :: Lens' (Foo a0) Int -- Defined at NewType_makeLenses.hs:9:1
> :i baz
baz :: Lens (Foo a0) (Foo a1) a0 a1 -- Defined at NewType_makeLenses.hs:10:1
$ git clone --depth=1 https://github.com/ghc/ghc.git && cd ghc
$ grep -C2 "\"Defined" -r . --exclude-dir=testsuite
./compiler/basicTypes/Name.hs-ppr_z_occ_name occ = ztext (zEncodeFS (occNameFS occ))
./compiler/basicTypes/Name.hs-
./compiler/basicTypes/Name.hs:-- Prints (if mod information is available) "Defined at <loc>" or
./compiler/basicTypes/Name.hs:-- "Defined in <mod>" information for a Name.
./compiler/basicTypes/Name.hs-pprDefinedAt :: Name -> SDoc
./compiler/basicTypes/Name.hs:pprDefinedAt name = text "Defined" <+> pprNameDefnLoc name
./compiler/basicTypes/Name.hs-
./compiler/basicTypes/Name.hs-pprNameDefnLoc :: Name -> SDoc
$ grep "data SDoc" -r . --exclude-dir=testsuite
./compiler/utils/Outputable.hs:data SDocContext = SDC
./compiler/utils/Outputable.hs-boot:data SDoc
printDoc :: Mode -> Int -> Handle -> Doc -> IO ()
-- printDoc adds a newline to the end
printDoc mode cols hdl doc = printDoc_ mode cols hdl (doc $$ text "")