Type ghci randomio output

I follow https://en.wikibooks.org/wiki/Haskell/Understanding_monads/State , and randomIOprints an integer in ghcidirectly. If its type is polymorphic, then how ghcidoes it know it Inthere? Are there any special rules for type inference ghci?

GHCi> :m System.Random
GHCi> :t randomIO
randomIO :: Random a => IO a
GHCi> randomIO
-1557093684
GHCi> randomIO
1342278538
+2
source share
1 answer

I believe this is just a restriction of monomorphism . Polymorphic types such as are Num a => atreated as Integerif the actual type is not specified. This rule probably also works in ghci, and you see an integer type instead of some unknown type variable.

UPD 1: , .

UPD 2: Random , . - default (Integer, Double), . ghci

Prelude System.Random> default ()
Prelude System.Random> randomIO

<interactive>:6:1:
    No instance for (Show (IO a0)) arising from a use ofprint
    In a stmt of an interactive GHCi command: print it
Prelude System.Random> default (Integer)
Prelude System.Random> randomIO
-7948113563809442883
Prelude System.Random> default (Double)
Prelude System.Random> randomIO
0.41581766590151104
0

Source: https://habr.com/ru/post/1659467/


All Articles