liveBook · Manning

Functional dependency

As explained in Functional Design and Architecture: Examples in Haskell

A functional dependency is a type-class declaration constraint stating that certain type parameters determine other type parameters.

Generic database code needs to work with entities whose concrete types are unknown. A functional dependency records that relationship at the type-class level: each entity type determines one database type. section 11.2.3

In `DBEntity db entity | entity -> db`, the declaration guarantees that an entity cannot be associated with multiple databases. The class also exposes associated `KeyEntity` and `ValueEntity` types for each entity. section 11.2.3

Extensible AstroDB entities

An `AstroDB` instance can associate `MeteorEntity` and `CometEntity` with their own key and value representations. Generic `loadEntity` code can then operate on either entity without changing the framework, while new entity instances extend the catalog independently.

How Functional Design and Architecture: Examples in Haskell covers it

How deep it goes
Defines declaration syntax and its type-level consequence, then applies it within a generic persistence design.
Examples
Uses AstroDB entities with distinct Meteor and Comet key and value representations.
What you can do after
Build extensible generic database entities whose types select the appropriate database and associated representations.
How it connects
Connects type classes, associated algebraic data types, generic programming, and key-value databases.

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.