开发者

Function to show a given value in "String" Form

How do I make a function to do the following?

showIt :: a -> String
showIt word = .......?

so that if I use

showIt "ant"

I get:

"ant"

in Haskell? I know I can use the show definition as 开发者_StackOverflowsuch for Ints

*Main> show 3
"3"


Make the "a" to implement Show type class

showIt :: (Show a) => a -> String
showIt = show


To convert myself to "myself" you need to put quotes around it. :)

Prelude> "myself"
"myself"

Update:

You can't implement method showIt :: a -> String in a useful way because a can be anything, including function. You can't show a function, can you?

You can, however, implmement showIt :: String -> String like this:

showIt word = word
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜