ghci randomio type inference

你离开我真会死。 提交于 2019-12-06 14:12:57

I suppose it is just simple Monomorphism restriction. Polymorphic types such as Num a => a are handled like Integer if actual type is not specified. Probably this rule also works in ghci and you see integer type instead of some unknown type variable.

UPD 1: actually the real answer contained under this part of user guide about defaulting rules.

UPD 2: Case with Random type class turned to be more difficult than I expected. So in this case defaulting rules are resolved due to default (Integer, Double) declaration which is said in report. Consider next ghci session

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

<interactive>:6:1:
    No instance for (Show (IO a0)) arising from a use of ‘print’
    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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!