📘
HPM Education - Haskell
  • Introduction to Haskell
  • Introduction
    • Functions
    • Functional Programming vs Imperative Programming
    • Installing Haskell
    • Haskell Modules
    • Loading Modules into GHCi
    • Expressions
    • Laziness
    • Immutability
  • Types in Haskell
    • Introduction
    • Basic Types
    • Static Type Check
    • Polymorphic and Overloaded Types
    • Data Structure Types
      • Lists
        • List Functions
      • Tuples
    • Function Types
      • Curried Functions
      • Partial Application
  • Defining Functions / Working with Functions
    • The Layout Rule
    • Local Definitions
    • The Infix Operator
    • Conditionals
      • If-then-else Statements
      • MultiWayIf
      • Guarded Equations
      • Case-of Statements
    • Pattern Matching
      • Tuple Patterns
      • List Patterns
    • Lambda functions
    • Function Operators
  • List Comprehensions
    • List Comprehensions
  • Higher-order Functions
    • Introduction
    • The map Function
    • The filter Function
  • Recursion
    • Introduction
    • 4 Steps to Defining Recursive Functions
    • Recursion Practice
    • Folds
      • Fold Right (foldr)
      • Fold Left (foldl)
  • Cutom Types
    • Declaring Types
      • Type Synonyms
      • Data Declarations
      • Newtype declarations
  • Type Classes
    • Introduction
    • Basic Classes
      • Eq – Equality Types
      • Ord – ordered types
      • Show – Showable Types
      • Read – readable types
      • Num – Numeric Types
      • Integral – Integral Types
      • Fractional – Fractional Types
      • Enum – Enumeration Types
    • Derived Instances
    • Exercise – Making a Card Deck Type
  • Interactive Programming
    • Introduction
    • Input / Output Actions
    • Sequencing Actions
    • Exercise - Numbers Guessing Game
  • Functors, Applicatives and Monads
    • Introduction
    • Functors
    • Applicative Functors
    • Monads
      • Maybe Monad
      • List Monad
      • Monad Laws
  • References / Further Reading
Powered by GitBook
On this page
  • Bool – logical values
  • Int – fixed-precision integers
  • Integer – arbitrary-precision integers
  • Float – single-precision floating-point numbers
  • Double – double-precision floating-point numbers
  • Char – single character
  • String – strings of characters

Was this helpful?

  1. Types in Haskell

Basic Types

Bool – logical values

Bool is a logical data type that can be either True or False.

Int – fixed-precision integers

Int can contain integers, both negative and positive whole numbers (e.g. -50, 50) up to a certain size which is limited by a fixed amount of memory, hence the term fixed-precision. GHC can hold values in the range of (-2^63) to (2^63 - 1) for Int types - going outside those ranges will yield unexpected results.

Integer – arbitrary-precision integers

Integer is the same as Int except it does not have a limit to the values it can hold. Performance-wise, it is better to use Int if we know our values will not go out of range, as most computers have built-in hardware for dealing with fixed-precision integers.

Float – single-precision floating-point numbers

Float can contain decimal numbers (e.g. -1.5, 6.23, 50.0) up to a certain precision which is limited by a fixed amount of memory. The term floating-point comes from this memory limitation, which limits the number of digits (precision) that can come after the decimal point based on the size of the number.

Double – double-precision floating-point numbers

Double is the same type as float, containing decimal numbers but with double the memory assigned for storage for increased precision.

Char – single character

Char is a type for characters – it can hold any Unicode character including control characters such as '\n' (a new line character) or '\t' (tab stop character). Char type values must be enclosed in single quotes ''.

String – strings of characters

Strings simply hold a string of characters – they are in fact a type [Char] (a list of Char type values) in Haskell. Strings must be enclosed in double-quotes "", e.g. "Haskell is great".

PreviousIntroductionNextStatic Type Check

Last updated 2 years ago

Was this helpful?