Haskell 我用错了吗?

Haskell 我用错了吗?,haskell,random,io,functional-programming,Haskell,Random,Io,Functional Programming,我试图在终端上显示一个介于1和7之间的随机数 nRandom :: IO () nRandom = do number <- randomRIO (1,7) putStrLn ("Your random number is: "++show number) nRandom::IO() nRandom=do 数字问题是randomRIO和show都是多态的,因此编译器不知道为number选择哪种类型。您可以添加类型批注,例如 nRandom :: IO () nRan

我试图在终端上显示一个介于1和7之间的随机数

nRandom :: IO ()
nRandom = do
    number <- randomRIO (1,7)
    putStrLn ("Your random number is: "++show number)   
nRandom::IO()
nRandom=do

数字问题是
randomRIO
show
都是多态的,因此编译器不知道为
number
选择哪种类型。您可以添加类型批注,例如

nRandom :: IO ()
nRandom = do
    number <- randomRIO (1,7) :: IO Int
    putStrLn ("Your random number is: "++show number)
nRandom::IO()
nRandom=do
数
No instance for (Num a0) arising from the literal `1'
The type variable `a0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Note: there are several potential instances:
  instance Num Double -- Defined in `GHC.Float'
  instance Num Float -- Defined in `GHC.Float'
  instance Integral a => Num (GHC.Real.Ratio a)
    -- Defined in `GHC.Real'
  ...plus 37 others
In the expression: 1
In the first argument of `randomRIO', namely `(1, 7)'
In a stmt of a 'do' block: number <- randomRIO (1, 7)
nRandom :: IO ()
nRandom = do
    number <- randomRIO (1,7) :: IO Int
    putStrLn ("Your random number is: "++show number)