开发者

Function to show a given value in "String" Form

开发者 https://www.devze.com 2023-03-09 12:10 出处:网络
How do I make a function to do the following? showIt :: a -> String showIt word = .......? so that if I use

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

精彩评论

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

关注公众号