Haskell Language Overloaded Literals Integer 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 Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

The type of the literal

Prelude> :t 1
1 :: Num a => a

choosing a concrete type with annotations

You can specify the type as long as the target type is Num with an annotation:

Prelude> 1 :: Int
1
it :: Int
Prelude> 1 :: Double
1.0
it :: Double
Prelude> 1 :: Word
1
it :: Word

if not the compiler will complain

Prelude> 1 :: String

<interactive>:
    No instance for (Num String) arising from the literal `1'
    In the expression: 1 :: String
    In an equation for `it': it = 1 :: String


Got any Haskell Language Question?