I know you can convert a String to an number with read:
Prelude> read "3" :: Int 3 Prelude> read "3" :: Double 3.0 But how do you grab the String representation of an Int value?
The opposite of read is show.
Prelude> show 3 "3" Prelude> read $ show 3 :: Int 3 Anyone who is just starting with Haskell and trying to print an Int, use:
module Lib ( someFunc ) where someFunc :: IO () x = 123 someFunc = putStrLn (show x) You can use show:
show 3 What I want to add is that the type signature of show is the following:
show :: a -> String And can turn lots of values into string not only type Int.
For example:
show [1,2,3] Here is a reference:
https://hackage.haskell.org/package/base-4.14.1.0/docs/GHC-Show.html#v:show