[Haskell-cafe] How to write a Monad instance for this type
frederic-emmanuel.picca at synchrotron-soleil.fr
Mon Sep 2 19:20:10 UTC 2019
Hello, I try to write a monad instance for this type which represent the content of an hdf5 file.
This file format is similar to a filesystem, where directories are Group and files Dataset.
I end up with this type.
data Hdf5M a
= H5Root (Hdf5M a)
| H5Group ByteString [Hdf5M a] -- A group can contain other groups and/or datasets
| forall sh b. (NativeType b, Shape sh) => H5Dataset ByteString (Array F sh b)
type Hdf5 = Hdf5M ()
hdf5 :: Hdf5 -> Hdf5
hdf5 = H5Root
group :: ByteString -> [Hdf5] -> Hdf5
group g = H5Group g
dataset :: (NativeType b, Shape sh) => ByteString -> (Array F sh b) -> Hdf5
dataset = H5Dataset
I tryed to inspire myself from the blaze-html Markup type.
And I would like to be able to describe a contain like this
hdf5 $ do
group "name" $ do
dataset "name1" array1
dataset "name2" array2
group "other-name" $ do
H5Root ( H5Group "name" [ dataset ]...)
the final idea, is to be able to serialize object via a
class ToHdf5 where
toHdf5 :: a -> Hdf5
So my question is someone can help me design this ?
thanks for your help
More information about the Haskell-Cafe