Увеличьте "ширину" 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

Есть ли способ установить максимальную длину строк?

Ответы

Ответ 1

Есть три параметра, которые управляют довольно печатной:

-dppr-debug         Turn on debug printing (more verbose)
-dppr-user-length   Set the depth for printing expressions in error msgs    
-dppr-cols⟨N⟩       Set the width of debugging output. For example -dppr-cols200

Вы ищете -dppr-cols. Его значение по умолчанию - 100. Вы можете установить его на любое другое значение, либо при вызове GHCi, либо с помощью :set.

Сравнение опций

Без -dppr-cols

$ ghci NewType_makeLenses.hs
[1 of 1] Compiling Main             ( NewType_makeLenses.hs, interpreted )  
Ok, modules loaded: Main.                                                   
> :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   

С -dppr-cols140

$ ghci -dppr-cols140 NewType_makeLenses.hs
[1 of 1] Compiling Main             ( NewType_makeLenses.hs, interpreted )
Ok, modules loaded: Main.
> :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

С :set -dppr-cols140

$ 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

Бонус: как я нашел это?

Я не смотрел на флаги, вместо этого я заглянул в исходный код GHC:

$ git clone --depth=1 https://github.com/ghc/ghc.git && cd ghc

Далее я ищу строку, начинающуюся с "Defined:

$ 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

SDoc кажется интересным.

$ grep "data SDoc" -r . --exclude-dir=testsuite
./compiler/utils/Outputable.hs:data SDocContext = SDC
./compiler/utils/Outputable.hs-boot:data SDoc

Outputable.hs включает printForUser, который использует pprCol dflags вместе с printDoc из Pretty. printDoc определяется как

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. Вы можете просто grep пройти через GHC:).