为什么不能使用hashUnique的Int值?

| 我想将hashUnique返回的值存储到列表中,但是我不能这样做:
import Data.Unique
import Data.List as L

cnter = do
   u <- newUnique
   return (hashUnique u)

main = cnter:[]
它将显示错误消息:
No instance for (Show (IO Int)), arising from a use of \'print\' at <interative>
    
已邀请:
        
cnter
是返回Int的IO操作。即,
cnter
的类型为
IO Int
。您正在尝试将其用作
Int
。您真正想要的是执行操作,获得ѭ5,然后使用该结果:
import Data.Unique
import Data.List as L

cnter = do
   u <- newUnique
   return (hashUnique u)

main = cnter >>= \\c -> print [c]
或带有符号:
main = do c <- cnter
          print [c]
但是我不确定为什么要构造一个列表以打印它,我个人只有9英镑:
main = cnter >>= print
    

要回复问题请先登录注册