Floating Numeral

Download haskell eBook

Example

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
1.0
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
<interactive>:
    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

Stats

Contributors: 3
2016-07-22
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook