如何使函数执行以下操作?以“字符串”形式显示给定值的函数形式
showIt :: a -> String
showIt word = .......?
所以,如果我用
showIt "ant"
我得到:
"ant"
在Haskell
?我知道我可以使用show
定义为这样的小号Int
*Main> show 3
"3"
如何使函数执行以下操作?以“字符串”形式显示给定值的函数形式
showIt :: a -> String
showIt word = .......?
所以,如果我用
showIt "ant"
我得到:
"ant"
在Haskell
?我知道我可以使用show
定义为这样的小号Int
*Main> show 3
"3"
充分利用 “一” 来实现显示类型的类
showIt :: (Show a) => a -> String
showIt = show
要转换myself
到"myself"
你需要把它周围的报价。 :)
Prelude> "myself"
"myself"
更新:
无法实现有用的方式方法showIt :: a -> String
因为a
可以是任何东西,包括函数。你不能显示功能,你能吗?
你可以,但是,implmement showIt :: String -> String
这样的:
showIt word = word
我不明白你的问题。你为什么不使用'show'? – fuz 2011-05-30 14:44:28