What is the difference between Haskell's Floating and Fractional classes?

What is the difference between classes Floatingand Fractionalin Haskell?

+4
source share
2 answers

Definitions Fractionaland Floatingcan be found in the Prelude documentation :

class Num a => Fractional a where
    (/) :: a -> a -> a
    recip :: a -> a
    fromRational :: Rational -> a 

Fractional numbers supporting real division.

[...]

class Fractional a => Floating a where
    pi :: a
    exp :: a -> a
    log :: a -> a
    sqrt :: a -> a
    (**) :: a -> a -> a
    logBase :: a -> a -> a
    sin :: a -> a
    cos :: a -> a
    tan :: a -> a
    asin :: a -> a
    acos :: a -> a
    atan :: a -> a
    sinh :: a -> a
    cosh :: a -> a
    tanh :: a -> a
    asinh :: a -> a
    acosh :: a -> a
    atanh :: a -> a

Trigonometric and hyperbolic functions and related functions.

[...]

So, to translate this into English: A Fractionalis any number for which I can define division:

(/) :: Fractional a => a -> a -> a

, , , ( ). Int, Int Int Int ( , ).

Fractional - Floating , . , , sin : a sin . (, sin 0) . , , (), .

+5

:

  • Fractional - , ( , , ) , , .
    , , ; Num, , .

  • Floating - , , .. . . Floating , , ( ).
    Floating Fractional, Floating ( , , ) .

: Floating , .. . , : ( ). , ( ± 10 300) .

Fractional . , Rational ( ) , " ". , sin log, .


, " ". Haskell . , , . : Num/Fractional/Floating - , // . , "" : , Word32 Int , , (2^70 :: Int) == 0, .. 2 64.

, Integer Rational, , .. . , , . , aern, .

+5

Source: https://habr.com/ru/post/1668437/


All Articles