diff --git a/src/library/PostgresqlConnectionString.hs b/src/library/PostgresqlConnectionString.hs index 9b12046..422022a 100644 --- a/src/library/PostgresqlConnectionString.hs +++ b/src/library/PostgresqlConnectionString.hs @@ -71,6 +71,9 @@ module PostgresqlConnectionString password, dbname, param, + + -- * Conversions + IsomorphicTo (..), ) where @@ -524,3 +527,25 @@ param key value = [] Nothing (Map.singleton key value) + +-- * Conversions + +-- | Type class for types that are isomorphic to 'ConnectionString'. +-- +-- Isomorphism laws apply: +-- +-- * @to . from = id@ +-- * @from . to = id@ +-- +-- This means that converting a value to 'ConnectionString' and back +-- should yield the original value, and vice versa. +class IsomorphicTo a where + -- | Construct 'ConnectionString' **from** type @a@. + -- + -- When imported qualified it reads naturally: @ConnectionString.from@. + from :: a -> ConnectionString + + -- | Convert 'ConnectionString' **to** type @a@. + -- + -- When imported qualified it reads naturally: @ConnectionString.to@. + to :: ConnectionString -> a