[Haskell-cafe] Serialize instance for System.Posix.Files.FileStatus
gtener at gmail.com
Wed Feb 1 16:10:16 CET 2012
I assume you speak about Serialize typeclass from cereal package and
FileStatus from unix package.
There are several problems with implementing such instance:
- FileStatus doesn't export the fact it's a newtype around Ptr CStat
- CStat isn't exported either
- there are no constructors for FileStatus or any way to change the value
- it could be implemented internally in unix but then it would have to
depend on cereal which is non-trivial change
So implementing such instance would basically mean heavy changes to unix
My advice: implement your own datatype with information equivalent to
FileStatus, say FileStatusData, along with function mkFileStatusData ::
FileStatus -> FileStatusData and provide instance for Serialize for
As for efficiency: I'm not sure it can be done in any better way. In
particular you can't be sure that on the system on which you are going to
deserialize the value the CStat structure has the same memory layout. So
you have to use proper serialization on Haskell side to achieve correctness.
On Wed, Feb 1, 2012 at 15:02, Johan Brinch <brinchj at gmail.com> wrote:
> Are there plans on implementing an efficient Serialize instance of the
> FileStatus type?
> I'm aware that it's just a wrapper around a C stat structure, and I
> reckon it can be done more efficiently than copying from C to Haskell
> for every value.
> Johan Brinch
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe