diff options
Diffstat (limited to 'packages/base/src/Internal/Static.hs')
-rw-r--r-- | packages/base/src/Internal/Static.hs | 14 |
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 | |||
35 | import Data.Proxy(Proxy) | 35 | import Data.Proxy(Proxy) |
36 | import Foreign.Storable(Storable) | 36 | import Foreign.Storable(Storable) |
37 | import Text.Printf | 37 | import Text.Printf |
38 | |||
38 | import Data.Binary | 39 | import Data.Binary |
39 | import GHC.Generics (Generic) | 40 | import GHC.Generics (Generic) |
41 | import 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 | ||
54 | instance (Binary a) => Binary (Dim n a) | 56 | instance (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 | ||
56 | lift1F | 68 | lift1F |
57 | :: (c t -> c t) | 69 | :: (c t -> c t) |