BudiBadu Logo
Samplebadu
Haskell

Learn Haskell by Examples

GHC 9.x

Haskell is an advanced, purely functional programming language. It features a strong, static type system with type inference and lazy evaluation.

These examples explore the core features of Haskell, from its expressive type system and pattern matching to its powerful list comprehensions and algebraic data types.

Type Signatures

Declaring explicit types for functions and values with this sample code demonstrating type signature syntax using double colon, curried function types with arrow notation, type inference capabilities, and IO type for side effects.

Pattern Matching

Deconstructing data with multiple function definitions through this code example showing pattern matching on literal values, list patterns for empty and non-empty cases, wildcard underscore for ignored values, and top-to-bottom pattern evaluation.

List Comprehensions

Creating and transforming lists concisely with this sample code demonstrating set-builder notation syntax, generators with left arrow operator, predicate filters for conditions, and multiple generators for Cartesian products.

Algebraic Data Types

Defining custom data structures with multiple constructors through this code example showing sum type declaration with pipe separator, value constructors with parameters, pattern matching on constructors, and deriving Show for string conversion.

Maybe Type

Handling optional values safely with this sample code demonstrating Maybe type with Just and Nothing constructors, pattern matching for value extraction, monadic do notation for chaining operations, and eliminating null pointer exceptions.

Lazy Evaluation

Working with infinite data structures through this code example demonstrating non-strict evaluation strategy, infinite list definitions, thunk creation for suspended computations, and demand-driven computation with take and filter.

Record Syntax

Defining data types with named fields through this code example showing record syntax declaration, auto-generated getter functions, record construction with field names, and immutable record updates creating new values.