【问题标题】:How can I get `ghci` to use my `show` function?如何让 `ghci` 使用我的 `show` 功能?
【发布时间】:2016-06-07 10:03:49
【问题描述】:

假设您想使用自己的显示功能(例如,let show = take 1000 . Prelude.show)。你怎么能允许ghci 使用它来打印而不是内置的show

【问题讨论】:

标签: haskell ghc read-eval-print-loop ghci


【解决方案1】:

您可以定义自己的interactive print 函数,例如:

module BetterPrint
betterPrint a = putStrLn (take 1000 $ show a)

然后启动 ghci 为

ghci -interactive-print=BetterPrint.betterPrint

【讨论】:

  • 专业提示:将ghci -interactive-print=BetterPrint.betterPrint 分配给别名。
  • 你也可以把它放在你的 ~/.ghci :set -interactive-print=betterPrint
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-02
  • 1970-01-01
  • 1970-01-01
  • 2017-12-12
  • 2019-01-25
相关资源
最近更新 更多