Here is my code:
func :: Integer -> String
func i = "LoadC R" ++ i ++ "\n"
But I got the error:
Couldn’t match expected type `[Char]’ with actual type `Integer’
How do I convert i to char?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
showto turn a number into a string:showworks on lots of things (but not all).To actually print this, you need to do
or if you’re using ghci (which I would recommend you use a lot while you write your code, testing everything as soon as you’ve written it), you can just write
and it will work. (I’ll explain why below.)
If you use
putStrLninstead ofputStrit puts an extra newline at the end.If you want a new line in what you’re printing, put
\nin it wherever you like.has lots of newlines in it.
Why does
putStrturn\ninto newlines? Well,putStrandputStrLnhave typeString -> IO ()meaning they turn the String they’re given into an IO program that puts it on the screen. In ghci, if you give it something of typeIO (), it’ll do it. If you give it something of another type it’llshowit and thenputStrthat. This means that if you typeit has the same effect as
whereas if you wanted the
\nto be a newline, you’d need to doto stop ghci from
showing it before putting it on the screen. (If you find yourself doing a lot ofputStr (show x), there’s a shortcut:print x.)