简体   繁体   English

Haskell - 如何投射类型?

[英]Haskell - how to cast types?

I am trying to do following: 我想做以下事情:

10 ** length xs * x

but I get: 但我得到:

No instance for (Floating Int) arising from a use of `**' 使用“**”时没有(Floating Int)的实例

You can use ^ to raise to an integral power. 你可以使用^来提升一个整体的力量。 There's no need to convert to float here. 这里没有必要转换为float。

Besides @sepp2k's answer , if you somehow really need to convert from an integer to some other types of Num, use fromIntegral . 除了@ sepp2k的答案 ,如果你真的需要从一个整数转换为其他类型的Num,请使用fromIntegral

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

10 ** fromIntegral (length xs) * x

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM