我如何在 Idris 中使用分数?
How can I use fractions in Idris?
当我尝试用一个整数除以另一个整数时,我收到以下消息:
Idris> 6 / 8
Can't find implementation for Fractional Integer
这到底是什么意思? 如何在 Idris 中使用有理数?
Idris does not have a built-in type for rational numbers. The error message you are seeing means that the (/)
function, which is a method of the Fractional
接口,要求其参数是实现该接口的类型;然而,目前唯一实现 Fractional
接口的类型是 Double
:
Idris> :doc Fractional
Interface Fractional
Parameters:
ty
Constraints:
Num ty
Methods:
(/) : Fractional ty => ty -> ty -> ty
infixl 9
The function is Total
recip : Fractional ty => ty -> ty
The function is Total
Implementations:
Fractional Double
当我尝试用一个整数除以另一个整数时,我收到以下消息:
Idris> 6 / 8
Can't find implementation for Fractional Integer
这到底是什么意思? 如何在 Idris 中使用有理数?
Idris does not have a built-in type for rational numbers. The error message you are seeing means that the (/)
function, which is a method of the Fractional
接口,要求其参数是实现该接口的类型;然而,目前唯一实现 Fractional
接口的类型是 Double
:
Idris> :doc Fractional
Interface Fractional
Parameters:
ty
Constraints:
Num ty
Methods:
(/) : Fractional ty => ty -> ty -> ty
infixl 9
The function is Total
recip : Fractional ty => ty -> ty
The function is Total
Implementations:
Fractional Double