Haskell Language Overloaded Literals Floating Numeral

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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


Got any Haskell Language Question?