简体   繁体   English

在 Haskell 中打印出 IO 操作中的某些类型

[英]Printing out the type of something in IO operations in Haskell

I have a block of code我有一个代码块

main = do
   args <- getArgs --args is a list.
   ...
   let finalMappedContents = addUpSameWord mappedContents 

For the final IO statement, I want to print out the type of finalMappedContents.对于最终的 IO 语句,我想打印出 finalMappedContents 的类型。 How can I do this?我怎样才能做到这一点? I know of the typeOf function, but I'm not completely sure how to use that here.我知道 typeOf 函数,但我不完全确定如何在这里使用它。

You can use showsTypeRep in order to get the String representation of the type:您可以使用showsTypeRep来获取该类型的String表示形式:

λ> let foo = "Foo"
λ> import Data.Typeable
λ> putStrLn $ showsTypeRep (typeOf foo) ""
[Char]

In your case it would be:在您的情况下,它将是:

putStrLn $ showsTypeRep (typeOf finalMappedContents) ""

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM