From f57e800a1d1a8e9f2bed34428f7f58a375f178fb Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 11 Jul 2021 17:56:34 +0200 Subject: WIP splitting of Target module and towards parallel builds --- Coolbal/DataVersionTag.hs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Coolbal/DataVersionTag.hs (limited to 'Coolbal/DataVersionTag.hs') 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)) -- cgit v1.2.3-70-g09d2