您好我想在列表中打印函数的名称。是否有可能这样做?
我的例子:
import Text.Show.Functions
f1 x = if x == 1 then 1 else 0
f2 x = if x == 2 then 1 else 0
f3 x = if x == 1 then 2 else 0
fs = [f1,f2,f3]
fs
写出[<function>,<function>,<function>]
,但我想要[f1,f2,f3]
答案 0 :(得分:3)
不,这是不可能的。如果你想要命名的功能,你必须自己鞭打它们; e.g。
data Named a = Named { name :: String, val :: a }
instance Show (Named a) where show = name
fs = [Named "f1" f1, Named "f2" f2, Named "f3" f3]