Closed l29ah closed 2 years ago
After printing a packed test UniverseView filled with ObjectNil's i'm totally confused:
ObjectArray [ObjectArray [ObjectArray [ObjectNil,ObjectNil,ObjectNil],ObjectNil,ObjectNil,ObjectNil],ObjectArray [ObjectNil,ObjectNil,ObjectNil],ObjectNil,ObjectNil,ObjectNil]
Why wasn't it placed in a flat array?
M1 {unM1 = M1 {unM1 = ((M1 {unM1 = K1 {unK1 = ObjectInt 0}} :: (M1 {unM1 = K1 {unK1 = ObjectInt 1}} :: M1 {unM1 = K1 {unK1 = ObjectInt 2}})) :: (M1 {unM1 = K1 {unK1 = ObjectInt 3}} :: (M1 {unM1 = K1 {unK1 = ObjectInt 4}} :: M1 {unM1 = K1 {unK1 = ObjectInt 5}}))) :: ((M1 {unM1 = K1 {unK1 = ObjectInt 6}} :: (M1 {unM1 = K1 {unK1 = ObjectInt 7}} :: M1 {unM1 = K1 {unK1 = ObjectInt 8}})) :: (M1 {unM1 = K1 {unK1 = ObjectInt 9}} :: (M1 {unM1 = K1 {unK1 = ObjectInt 10}} :*: M1 {unM1 = K1 {unK1 = ObjectInt 11}})))}}
mmkay; i wonder if the simplest solution would be rewriting it in https://hackage.haskell.org/package/generics-sop, as i don't see how to flatten this properly; i have no experience with generics tho.
I've "fixed" serializing with
diff --git a/src/Data/MessagePack/Types/Generic.hs b/src/Data/MessagePack/Types/Generic.hs
index 059971b..91fc305 100644
--- a/src/Data/MessagePack/Types/Generic.hs
+++ b/src/Data/MessagePack/Types/Generic.hs
@@ -8,6 +8,7 @@
{-# LANGUAGE Safe #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
+{-# LANGUAGE UndecidableInstances #-}
module Data.MessagePack.Types.Generic () where
import Control.Applicative (Applicative, (<$>), (<*>))
@@ -28,7 +29,7 @@ instance GMessagePack U1 where
gFromObject ObjectNil = return U1
gFromObject _ = fail "invalid encoding for custom unit type"
-instance (GMessagePack a, GProdPack b) => GMessagePack (a :*: b) where
+instance (GProdPack a) => GMessagePack (a) where
gToObject = toObject . prodToObject
gFromObject = fromObject >=> prodFromObject
@@ -65,8 +66,8 @@ class GProdPack f where
-> m (f a)
-instance (GMessagePack a, GProdPack b) => GProdPack (a :*: b) where
- prodToObject (a :*: b) = gToObject a : prodToObject b
+instance (GProdPack a, GProdPack b) => GProdPack (a :*: b) where
+ prodToObject (a :*: b) = prodToObject a ++ prodToObject b
prodFromObject (a : b) = (:*:) <$> gFromObject a <*> prodFromObject b
prodFromObject [] = fail "invalid encoding for product type"
but deserializing is broken.
I'm trying to unpack msgpack into my type that has no lists:
On running my program, i get this:
This behaviour seems incorrect. The code employed is
It woks ok if i decode it as an
Object
. The printedObject
has a top-level array with the same number of items as my data type: http://dpaste.com/0F6045T