[Haskell-cafe] Serialize instance for System.Posix.Files.FileStatus

Krzysztof Skrzętnicki 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
of it
- 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
package.

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
FileStatusData.

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.

Best regards,
Krzysztof Skrzętnicki

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
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120201/e7968cc6/attachment.htm>


More information about the Haskell-Cafe mailing list