liveBook · Manning

Hydra

As explained in Functional Design and Architecture: Examples in Haskell

Hydra is the book's framework for structuring safe business logic with composable monadic languages and controlled effects.

Hydra is an application framework for structuring testable, maintainable business logic in concurrent web servers and command-line applications. It organizes effects such as database access, logging, state handling, concurrency, and error processing through composable monadic approaches. section 9.0

Safe business logic makes failures explicit rather than calling uncontrolled error functions. Domain exceptions can be thrown with throwException and contained with runSafely, producing an explicit Either result while keeping native exception handling behind the framework. section 15.2.3

Safely loading a game session

A loading scenario retrieves a labyrinth and player position, runs each action with runSafely, converts failures into Left values, and creates mutable state only when both loads succeed.

Listing 15.15 Updated white-box test that uses a real runtime
spec :: Spec
spec
  = around withAppRuntime
  $ describe "Labyrinth KV DB tests"
  $ it "Load player position should throw exception" 
  $ \appRt -> do
  
    mocksVar <- newIORef
      [ (0, RunRealInterpreter)                    #1
      , (1, Mock (MockedKVDBConn "LabKVDB"))       #2
      , (2, Mock (Right testKVDBLabyrinth))
      , (3, RunRealInterpreter)                    #3
      , (4, Mock (MockedKVDBConn "LabKVDB"))       #4
      , (5, Mock (Left (DBError "KVDB Failure")))
      , (6, RunRealInterpreter)                    #5
      ]
  
    let testRt = TestRuntime (Just appRt) mocksVar
    let action = loadGame testKVDBConfig 1
  
    eGameState <- try (Test.runAppL testRt action)
    case eGameState of
      Left (e :: SomeException) -> 
         show e `shouldBe` "Failed to load the player pos"
      Right _ -> fail "Test failed"

The updated white-box test combines a real application runtime with targeted database mocks, showing how Hydra tests logic across an interpreter hierarchy. section 15.2.3

How Functional Design and Architecture: Examples in Haskell covers it

How deep it goes
Explains framework architecture, effect handling, exception control, interpreters, and white-box testing, but not every subsystem implementation.
Examples
Uses game-session loading, labyrinth persistence, player-position failures, application runtimes, and mocked database operations.
What it assumes
Builds on free monads, monad transformers, final tagless, ReaderT, database effects, and basic exception handling.
What you can do after
Builds and tests explicit business workflows that isolate effects, model domain failures, and run safely through configurable interpreters.
How it connects
Connects free monads, final tagless, ReaderT, dependency injection, SQL, key-value databases, concurrency, and reactive programming.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Design and Architecture: Examples in Haskell. The section links point to the parts of the book it draws on.