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 Int
s
*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
精彩评论