开发者

Haskell - how to cast types?

I am trying to do following:

10 ** length xs * x

but I get:

No instance for (Floating Int) ar开发者_JAVA技巧ising from a use of `**'


You can use ^ to raise to an integral power. There's no need to convert to float here.


Besides @sepp2k's answer, if you somehow really need to convert from an integer to some other types of Num, use fromIntegral.

-- # fromIntegral :: (Integral a, Num b) => a -> b

10 ** fromIntegral (length xs) * x
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜