Safe Haskell | None |
---|---|
Language | Haskell2010 |
Versioning.Base
Description
This module provides some tools to encode multiple versions
of a data model in a single data-type parametrized by version number.
The addition or removal of a field can be expressed through the
Since
and Until
type families.
Example:
data Rec v = Rec { foo :: Int -- this field exists in all versions , bar :: Since V2 v Bool -- this field has been introduced in V2 , baz :: Until V2 v Double -- this field has been removed in V3 }
Besides reducing the number of data declarations, this approach also has other advantages:
- It makes migrations declarative and self-documenting.
- It allows for less verbose version-upcasting functions, since the fields that have a non-parametric type do not need to be copied.
- It is a foundation on which other useful abstractions can be built.
Please note that some classes may require a separate standalone deriving clause for each version of a data-type or some kind of inductive deriving mechanism.
Synopsis
- data V
- type family VPred (v :: V) :: V where ...
- type VSucc = 'VSucc
- type family VNat (v :: V) :: Nat where ...
- type family VCmp (v :: V) (w :: V) :: Ordering where ...
- type family Since (s :: V) (v :: V) a where ...
- type family SinceS (s :: V) (v :: V) a where ...
- type family Until (u :: V) (v :: V) a where ...
- type family UntilS (u :: V) (v :: V) a where ...
- type NA = Maybe Bare
- na :: NA
- type V0 = 'VZero
- type V1 = 'VSucc V0
- type V2 = 'VSucc V1
- type V3 = 'VSucc V2
- type V4 = 'VSucc V3
- type V5 = 'VSucc V4
- type V6 = 'VSucc V5
- type V7 = 'VSucc V6
- type V8 = 'VSucc V7
- type V9 = 'VSucc V8
- type V10 = 'VSucc V9
- type V11 = 'VSucc V10
- type V12 = 'VSucc V11
- type V13 = 'VSucc V12
- type V14 = 'VSucc V13
- type V15 = 'VSucc V14
- type V16 = 'VSucc V15
- type V17 = 'VSucc V16
- type V18 = 'VSucc V17
- type V19 = 'VSucc V18
- type V20 = 'VSucc V19
- versionNumber :: forall a v. KnownNat (VNat v) => a v -> Natural
Types
The version of a data model
type family VNat (v :: V) :: Nat where ... Source #
Get the type-level natural of a version
Equations
VNat v = VNat' v 0 |
type family Since (s :: V) (v :: V) a where ... Source #
This allows us to express that a field is only present since a given version. The first parameter is the version in which the field has been introduced, the second parameter is the actual version of the data-type.
type family Until (u :: V) (v :: V) a where ... Source #
This allows us to express that a field is only present until a given version. The first parameter is the last version in which the field is present, the second parameter is the actual version of the data-type.