Hardcoding in structural way

August 12, 2026 &english @shorts #haskell

Sometimes you need to use hardcoded string literals in your program. There is just not enough benefit of introducing dynamic configuration (config files, CLI options, etc), because values almost never change. And if they would change, it is easy to modify values in the source code.

I came up with the following pattern or keeping related configuration values close to each other.

data ClientImport a = (AsRelation a) => ClientImport
  { forecast  :: a
  , inventory :: a
  , products  :: a
  , reports   :: a
  }

clientImport :: ClientImport TableRelation
clientImport =
  ClientImport
    { forecast  = define "forecast"
    , inventory = define "inventory"
    , products  = define "products"
    , reports   = define "reports_legacy"
    }
  where
    define nm = TableRelation $ "client_imports" <> nm

The reason of introducing a data structure would be obvious after looking at usage site.

{-# LANGUAGE OverloadedRecordDot #-}

import Project.Legacy qualified as Legacy

available = do
  source <- from Legacy.clientImport.inventory

  where_ $ source ^^. "status" !=. lit Sold

OverloadedRecordDot extensions allows to have two dots in Legacy.clientImport.inventory, where

  • Legacy is a qualified alias of the Project.Legacy import
  • clientImport is a function name imported from Project.Legacy, has type ClientImport TableRelation
  • inventory is a field name accessor of the ClientImport data structure