Comparisment

   - compare programming languages by example

3

Integer literals

The syntax for literal integers.

Created by sam

Add a new answer

Either add an answer for a new language or add an alternative solution.
A description is only necessary when the code is not suitably 'obvious' or to justify an alternative approach.

Haskell

1
2 :: Num a => a
3 :: Int

Numeric literals may be used to represent "Int" values. Their type however is more general "Num a => a", meaning the same syntax may be used for any other instance of the Num typeclass such as Float, Double, etc. When ambiguous, a type signature can be given with ":: Int" to specialise the type. Numeric literals have special type defaulting rules meaning that if the type is ambigous then the type is first taken as "Int", and second as "Double". These rules can be overiden by making a "default" declaration.

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.

C

0b101010

Binary.

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.

C

052

Octal.

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.

C

0x2a

Hexadecimal.

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.

C

42

Decimal.

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.