I want to store the value returned from hashUnique into a list, but I can’t do that:
import Data.Unique
import Data.List as L
cnter = do
u <- newUnique
return (hashUnique u)
main = cnter:[]
It will give out the error message : No instance for (Show (IO Int)), arising from a use of 'print' at <interative>
cnteris an IO action that returns an Int. That is,cnterhas typeIO Int. You are trying to use it as anInt. What you really want is to execute the action, obtaining theInt, and then use that result:Or with do notation:
But I’m not sure why you want to construct a list just to print it, I’d just
print c, personally: