如何让`ghci`使用我的`show`功能?

PyR*_*lez 8 haskell ghc ghci read-eval-print-loop

假设你想使用自己的show函数(例如let show = take 1000 . Prelude.show).你如何允许ghci使用它来打印而不是内置show

Lee*_*Lee 12

您可以定义自己的交互式打印功能,例如:

module BetterPrint
betterPrint a = putStrLn (take 1000 $ show a)
Run Code Online (Sandbox Code Playgroud)

然后开始ghci为

ghci -interactive-print=BetterPrint.betterPrint
Run Code Online (Sandbox Code Playgroud)