Haskell: Show screwed up?

前端 未结 6 507
小鲜肉
小鲜肉 2021-01-17 17:34

The show function in Haskell doesn\'t seem to do what it should:

Prelude> let str = \"stack\\n\\noverflow\"
Prelude> putStrLn str
stack


overfl         


        
6条回答
  •  -上瘾入骨i
    2021-01-17 18:01

    The contract of the show method in Haskell is that it produce a string that, when evaluated, yields the value that was shown.

    Prelude> let str = "stack\n\noverflow"
    Prelude> putStrLn str
    stack
    
    overflow
    Prelude> putStrLn (show str)
    "stack\n\noverflow"
    Prelude> 
    

提交回复
热议问题