Haskell Language Floating Numeral

Download Haskell Language for free


The type of the literal

Prelude> :t 1.0
1.0 :: Fractional a => a

Choosing a concrete type with annotations

You can specify the type with a type annotation. The only requirement is that the type must have a Fractional instance.

Prelude> 1.0 :: Double
it :: Double
Prelude> 1.0 :: Data.Ratio.Ratio Int
1 % 1
it :: GHC.Real.Ratio Int 

if not the compiler will complain

Prelude> 1.0 :: Int
    No instance for (Fractional Int) arising from the literal `1.0'
    In the expression: 1.0 :: Int
    In an equation for `it': it = 1.0 :: Int
Integer Numeral