我怎样才能在Idris中使用分数?

时间:2017-07-23 01:53:04

标签: fractions idris

当我尝试将一个整数除以另一个整数时,我收到以下消息:

Idris> 6 / 8
Can't find implementation for Fractional Integer

这究竟是什么意思? 如何在Idris中使用有理数字?

1 个答案:

答案 0 :(得分:2)

Idris does not have a built-in type for rational numbers.您看到的错误消息意味着(/)函数(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