开发者

Haskell - how to cast types?

开发者 https://www.devze.com 2022-12-31 02:01 出处:网络
I am trying to do following: 10 ** length xs * x but I get: No instance for (Floating Int) ar开发者_JAVA技巧ising

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

精彩评论

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

关注公众号