liveBook · Manning

Configuration

As explained in Learn Haskell by Example

A configuration is structured application data containing settings such as paths, file restrictions, and resource bounds.

A configuration is structured application data that supplies a file-synchronization program with source and destination paths, an optional file-type restriction, and optional recursion and transfer limits. section 15.1.1

Listing 15.1 A type for configuring the file synchronization application
module App.Types where

import System.FileType (FileType)     #1

data Config = Config
  { configFromPath :: FilePath,        #2
    configToPath :: FilePath,          #2
    configRequiredFileType :: Maybe FileType,      #3
    configMaxRecursionDepth :: Maybe Int,       #4
    configMaxTransferredFiles :: Maybe Int     #4
  }
  deriving (Show, Eq)

The Config record groups paths, an optional FileType, and optional Int bounds into one value that actions can read. section 15.1.1

Use configuration in two stages:

  • Pass Config explicitly to actions when direct access is sufficient, using record pattern matching to expose its fields. section 15.1.1
  • Use ReaderT Config IO when many actions need the same read-only environment; run the application with runReaderT and lift ordinary IO operations. section 15.1.1
  • Keep configuration distinct from mutable synchronization state and accumulated file reports, which require different data interactions. section 15.1

How Learn Haskell by Example covers it

How deep it goes
Defines a concrete record and contrasts explicit passing with ReaderT, while deferring broader synchronization implementation details.
Examples
Uses a Config record containing paths, optional limits, and a file type, plus a ReaderT action printing source and destination paths.
What you can do after
Apply it via ReaderT and run configuration-dependent IO actions without repeating the environment argument.
How it connects
Connects configuration with Reader, ReaderT, IO, monad transformers, mutable state, and accumulated output.

Also explained in

Compare how 23 books explain configuration →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.