Haskell: Converting Int to String

前端 未结 3 970
闹比i
闹比i 2020-12-22 17:20

I know you can convert a String to an number with read:

Prelude> read \"3\" :: Int
3
Prelude> read \"3\" :: Double 
3.0
         


        
3条回答
  •  再見小時候
    2020-12-22 18:03

    An example based on Chuck's answer:

    myIntToStr :: Int -> String
    myIntToStr x
        | x < 3     = show x ++ " is less than three"
        | otherwise = "normal"
    

    Note that without the show the third line will not compile.

提交回复
热议问题