dimanche 3 janvier 2021

Why random number in haskell using randomRIO giving error?

I am trying to print random number between 0 and 1 but the code is giving error. I'm unable to understand what am I doing wrong.

import System.Random
main = print (randomRIO (1,0))

error: • No instance for (Show (IO a0)) arising from a use of ‘print’ • In the expression: print (randomRIO (1, 0)) In an equation for ‘main’: main = print (randomRIO (1, 0)) | 2 | main = print (randomRIO (1,0)) | ^^^^^^^^^^^^^^^^^^^^^^^

error: • Ambiguous type variable ‘a0’ arising from a use of ‘randomRIO’ prevents the constraint ‘(Random a0)’ from being solved. Probable fix: use a type annotation to specify what ‘a0’ should be. These potential instances exist: instance Random Integer -- Defined in ‘System.Random’ instance Random Bool -- Defined in ‘System.Random’ instance Random Char -- Defined in ‘System.Random’ ...plus four others ...plus 29 instances involving out-of-scope types (use -fprint-potential-instances to see them all) • In the first argument of ‘print’, namely ‘(randomRIO (1, 0))’ In the expression: print (randomRIO (1, 0)) In an equation for ‘main’: main = print (randomRIO (1, 0))

error: • Ambiguous type variable ‘a0’ arising from the literal ‘1’ prevents the constraint ‘(Num a0)’ from being solved. Probable fix: use a type annotation to specify what ‘a0’ should be. These potential instances exist: instance Num Integer -- Defined in ‘GHC.Num’ instance Num Double -- Defined in ‘GHC.Float’ instance Num Float -- Defined in ‘GHC.Float’ ...plus two others ...plus 35 instances involving out-of-scope types (use -fprint-potential-instances to see them all) • In the expression: 1 In the first argument of ‘randomRIO’, namely ‘(1, 0)’ In the first argument of ‘print’, namely ‘(randomRIO (1, 0))’ | 2 | main = print (randomRIO (1,0)) | ^




Aucun commentaire:

Enregistrer un commentaire