diff options
author | Tom Smeding <tom@tomsmeding.com> | 2021-07-11 17:56:34 +0200 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2021-07-11 17:56:34 +0200 |
commit | f57e800a1d1a8e9f2bed34428f7f58a375f178fb (patch) | |
tree | 7164b0a9bcf03703a6a7f44f5fa04e5847d876e5 /Coolbal/DataVersionTag.hs | |
parent | 317f1e27688a082926f39ec897f5a38d01a07ce7 (diff) |
Diffstat (limited to 'Coolbal/DataVersionTag.hs')
-rw-r--r-- | Coolbal/DataVersionTag.hs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Coolbal/DataVersionTag.hs b/Coolbal/DataVersionTag.hs new file mode 100644 index 0000000..a994e90 --- /dev/null +++ b/Coolbal/DataVersionTag.hs @@ -0,0 +1,22 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE KindSignatures #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeOperators #-} +module Coolbal.DataVersionTag where + +import Data.Binary +import GHC.TypeNats + + +data DataVersionTag (n :: Nat) = DataVersionTag + deriving (Show, Eq, Ord) + +instance (KnownNat n, n <= 255) => Binary (DataVersionTag n) where + put v = putWord8 (fromIntegral (natVal v)) + get = do + b <- getWord8 + let result = DataVersionTag :: DataVersionTag n + if b == fromIntegral (natVal result) + then return result + else fail ("DataVersionTag: read version " ++ show b ++ ", application expects version " ++ show (natVal result)) |