我有一些我想要打印的数据(有些是Maybe,有些则不是),我正在尝试创建一个通用的showField函数,如下所示:
showField :: (Show a) => a -> Text
showField x
| isJust x = Text.pack $ show $ fromJust x
| isNothing x = "None"
| otherwise = Text.pack $ show x
Run Code Online (Sandbox Code Playgroud)
这是一个严格的类型错误:
• Couldn't match expected type ‘Maybe a0’ with actual type ‘a’
‘a’ is a rigid type variable bound by
the type signature for:
showField :: forall a. Show a => a -> Text
at /data/users/jkozyra/fbsource/fbcode/experimental/jkozyra/hs/holdout_cleanup/HoldoutReaper.hs:244:18
• In the first argument of ‘isNothing’, namely ‘x’
In the …Run Code Online (Sandbox Code Playgroud)