我想使用
一种解决方法是在我想要放置跟踪的函数的签名中添加 "
但如果我可以使用一些
这是我定义一个
Debug.Trace.trace
来打印我知道是 Show
的内容。就像我在 Python 等语言中所做的那样。一种解决方法是在我想要放置跟踪的函数的签名中添加 "
Show a =>
",并在调用它的任何函数中添加该参数等。但如果我可以使用一些
debugShow
函数来调用 show
如果该值存在,则返回 "--no show--"
或类似的东西,那将会更好。这是我定义一个
DebugShow
的失败尝试(GHC 拒绝了 "重复实例声明"):{-# LANGUAGE FlexibleInstances, UndecidableInstances, OverlappingInstances #-}
class DebugShow a where
debugShow :: a -> String
instance Show a => DebugShow a where
debugShow = show
instance DebugShow a where
debugShow = const "--no show--"
某种“不安全转换”也可以解决我的问题。
有什么建议吗?
注意-这仅用于调试目的。我不会在任何完成的代码中使用此功能。