summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSidharth Kapur <sidharthkapur1@gmail.com>2016-03-13 17:25:23 -0500
committerSidharth Kapur <sidharthkapur1@gmail.com>2016-03-13 17:25:23 -0500
commit91e9c879bfa3b509cd737ba31580cbba0c0bf340 (patch)
treeea2243a1bd1e8618cf4b2c3e4c8a3e692e151f01
parent3824df2f2f17c8395832b88b27d61fdc22553f2e (diff)
Add dimension check in Dim binary instance
-rw-r--r--packages/base/src/Internal/Static.hs14
1 files changed, 13 insertions, 1 deletions
diff --git a/packages/base/src/Internal/Static.hs b/packages/base/src/Internal/Static.hs
index 058b9d0..a0af085 100644
--- a/packages/base/src/Internal/Static.hs
+++ b/packages/base/src/Internal/Static.hs
@@ -35,8 +35,10 @@ import Control.DeepSeq
35import Data.Proxy(Proxy) 35import Data.Proxy(Proxy)
36import Foreign.Storable(Storable) 36import Foreign.Storable(Storable)
37import Text.Printf 37import Text.Printf
38
38import Data.Binary 39import Data.Binary
39import GHC.Generics (Generic) 40import GHC.Generics (Generic)
41import Data.Proxy (Proxy(..))
40 42
41-------------------------------------------------------------------------------- 43--------------------------------------------------------------------------------
42 44
@@ -51,7 +53,17 @@ instance Binary a => Binary (Complex a)
51 put (r :+ i) = put (r, i) 53 put (r :+ i) = put (r, i)
52 get = (\(r,i) -> r :+ i) <$> get 54 get = (\(r,i) -> r :+ i) <$> get
53 55
54instance (Binary a) => Binary (Dim n a) 56instance (KnownNat n, Binary a) => Binary (Dim n a) where
57 get = do
58 k <- get
59 let n = natVal (Proxy :: Proxy n)
60 if n == k
61 then Dim <$> get
62 else fail ("Expected dimension " ++ (show n) ++ ", but found dimension " ++ (show k))
63
64 put (Dim x) = do
65 put (natVal (Proxy :: Proxy n))
66 put x
55 67
56lift1F 68lift1F
57 :: (c t -> c t) 69 :: (c t -> c t)