0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Haskell] ダブルクォーテーション (") を付けずに文字列を表示する

Last updated at Posted at 2023-09-25

String 型の文字列をそのまま表示したい場合は以下のようにします:

  • print でなく putStrLn を用いる
  • show は 不要

printputStrLn . show と同じ動作をするため、print . show としてしまうと putStrLn . show . show という意味になります。

文字列型以外では print のみを使用するか、または show の戻り値を putStrLn に渡します。

main :: IO ()
main = do

    let string = "foo" :: String
    putStrLn (show string :: String)
    print string
    putStrLn string -- そのまま表示

    let int = 23 :: Int
    print (show int :: String)
    print int                     -- そのまま表示
    putStrLn (show int :: String) -- そのまま表示

※説明のために show の戻り値の型 String を明示していますが、実際は不要です。

実行結果
"foo"
"foo"
foo
"23"
23
23

参考「putStrLn - System.IO
参考「print - System.IO
参考「show - Text.Show

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?