在Haskell,这个工程:理解为什么A/B不工作,但fromInteger A/fromInteger B则
ghci>5/2
2.5
大。但如果我分配5和2变量..
Main> let a = 5
Main> let b = 2
Main> a/b
<interactive>:68:2:
No instance for (Fractional Integer)
arising from a use of `/'
Possible fix: add an instance declaration for (Fractional Integer)
In the expression: a/b
In an equation for `it': it = a/b
Main>
我得到错误了wazoo。我能解决的唯一方法是说:
*Main> fromInteger a/fromInteger b
2.5
*Main>
fromInteger发生了什么事?为什么我需要它来完成这项工作?
你从哪里找到'-XNoMonomorphismRestriction',我在哪里可以找到更多像这样的东西,还有其他问题? – CodyBugstein 2013-04-28 20:44:03
@Imray:GHC用户指南很长很密集,但充满了这样的有用工具。尝试http://www.haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html。 Haskell wiki也有很多很棒的信息,但它更加分散。 – amindfv 2013-04-29 05:16:09