【发布时间】:2012-05-11 12:18:57
【问题描述】:
我目前正在尝试为原始算术函数编写一个小的 Show 实例。
目标是制作可显示的函数列表。
非常简单的 show 函数如下所示:
showOp :: (Int -> Int -> Int) -> String
showOp op
| op 3 3 == 6 = "plus"
| op 3 3 == 0 = "minus"
| op 3 3 == 9 = "times"
| op 3 3 == 1 = "divide"
| otherwise = "undefined"
但我无法获得 Show for (Int -> Int -> Int) 的实例。我是这样试的:
instance Show (Int -> Int -> Int) where
show op = show "asdf"
但它不起作用。 WinHugs 只是返回错误
Syntax error in instance head (variable expected)
甚至可以为函数定义 Show 吗?如果是,我该如何解决这个问题?
【问题讨论】:
标签: haskell