I have the following function:
probIndex idx xs =
xs!!idx+mult
where mult = round(2**idx)
When I try to load it in ghci, it shows the following error:
Prelude> :load bn.hs
[1 of 1] Compiling Main ( bn.hs, interpreted )
bn.hs:31:16:
No instance for (RealFrac Int)
arising from a use of `round'
Possible fix: add an instance declaration for (RealFrac Int)
In the expression: round (2 ** idx)
In an equation for `mult': mult = round (2 ** idx)
In an equation for `probIndex':
probIndex idx xs
= xs !! idx + mult
where
mult = round (2 ** idx)
bn.hs:31:23:
No instance for (Floating Int)
arising from a use of `**'
Possible fix: add an instance declaration for (Floating Int)
In the first argument of `round', namely `(2 ** idx)'
In the expression: round (2 ** idx)
In an equation for `mult': mult = round (2 ** idx)
Failed, modules loaded: none.
Prelude>
Why does it occur? 2**idx
returns float, but round
converts it to integer, so everything is an integer. Where do those "Floating
" and "RealFrac
" come from?