无法将 Complex Int 提升到 power

Cannot raise Complex Int to power

似乎将 Complex Int 提升为某次幂在其实例中违反了某些契约。我错了吗?

下面的最小示例

compl :: Complex Int -> Maybe (Complex Int)
compl d = (d^) <$> Just 3

错误信息:

No instance for (RealFloat Int) arising from an operator section
      In the first argument of ‘(<$>)’, namely ‘(d ^)’
      In the expression: (d ^) <$> Just 3
      In an equation for ‘compl’: compl d = (d ^) <$> Just 3

有什么办法解决这个问题吗?允许此类型为浮点数在我的程序中没有任何意义。

(^)Num的一个方法。 The Complex type's instantiation of Num 声明为:

instance RealFloat a => Num (Complex a)

也就是说,您不能将 Complex a 视为 Num,除非 aRealFloat,而 Int 不是。请改用 Complex Double 等。