Ok, I think I see the problem here. The vector-binary-examples package defines:
instance (Data.Vector.Generic.Base.Vector va, Binary a) => Binary (va)
which is very bad. This definition means "for any type of" va ", it is a valid binary instance." This means that this instance is available for any type that matches va . This includes (but is not limited to) all lists, all functors, and all monads. As a demonstration, ghci reports the following:
Prelude Data.Binary Data.Vector.Binary Data.ByteString.Lazy> :t getChar getChar :: IO Char Prelude Data.Binary Data.Vector.Binary Data.ByteString.Lazy> encode getChar <interactive>:1:0: No instance for (Data.Vector.Generic.Base.Vector IO Char) arising from a use of `encode' at <interactive>:1:0-13 Possible fix: add an instance declaration for (Data.Vector.Generic.Base.Vector IO Char) In the expression: encode getChar In the definition of `it': it = encode getChar
Here the interpreter is trying to use this instance for getChar :: IO Char , which is obviously not true.
Short answer: don't use vector binary instances yet. This instance does not work, and given how the instances are distributed through Haskell code, this will cause problems. Until this is fixed, you must write your own binary instances for the vectors. You should be able to copy code from vector binary instances and restrict it to a monomorphic vector type
instance (Binary a) => Binary (Vector a) where
I believe that this will work with any vector that is an instance of Data.Vector.Generic.Vector.
You can also refer to the constructor of vector-binary instances about this.
John l
source share